\chapter{Unit 1}
\section{Plane Curves \& Parametrics}
\subsection{Definition}
Typically, functions come in rectangular form, meaning $x$ is the independent
variable, and $y$ is dependent upon it. These functions look recognizable:
$y=\ln(x)$.

To track more things, or place a function into a seperate independent variable,
parametrics are used. When using parametrics, one function is given for every
graphed dimension. For example: $x=f(t)$, $y=f(t)$ or $x=f(\theta)$,
$y=f(\theta)$.

In the above example, $x(t)$ and $y(t)$ are the parametric equations and $t$ is
the parameter. The set of points $(x, y)$ obtained as $t$ varries over the
interval on which it is defined, is the graph of the parametric equation.

\subsection{De-parameterizing}
\begin{description}
  \item[Table] A table of values can be created where $t$ varries independently,
    and $(x(t), y(t))$ are the output values.
  \item[Algebraic Simplification] $x(t)$ can be simplified in terms of $y$ and
    substituted back into $y(t)$ to obtain a function.
  \item[Trigonometric Simplification] Trigonometric identities (such as
    $\sin^2\theta + \cos^2\theta = 1$, etc.) may be used to simplify the
    parameter functions.
\end{description}

\subsection{Parameterizing}
To obtain the parametric curve of the rectangular equation, the
following process is implemented:

\begin{enumerate}
  \item Let $x(t) = t$, and write $y(t)$ in terms of $x(t)$.
  \item Write both $x$ and $y$ in terms of $t$ and $m=\frac{dy}{dx}$.
\end{enumerate}

An example is shown below for the curve $y=1-x^2$:

\begin{align*}
  x(t) &= t\\
  y(t) &= 1-x^2\\
       &= 1-t^2\\\\
  m &= \frac{dy}{dx}=-2x\\\\
  x &= \frac{-m}{2}\\\\
  y &= 1-x^2\\
    &= 1-(\frac{-m}{2})^2\\
    &= 1-\frac{m^2}{4}
\end{align*}

\section{Parametric Equations and Calculus}
\subsection{The Derivative}
Suppose a parametric equation is given $x=f(t)$ and $y=g(t)$. The slope of that
equation is given to be:
\begin{equation}
  \frac{dy}{dx}=\frac{\frac{dy}{dt}}{\frac{dx}{dt}}
\end{equation}

The second derivative, therefore, of a parametric curve is given to be:
\begin{equation}\begin{aligned}
  \frac{d^2y}{dx^2} &=
  \frac{d}{dx}\left(\frac{\frac{dy}{dt}}{\frac{dx}{dt}}\right)\\
  &= \frac{d}{dx}\left(\frac{dy}{dx}\right)
\end{aligned}\end{equation}

\subsection{Arc Length}
Recall that the formula for arc length of a curve $h(x)$ over $[x_o, x_1]$ is:
\begin{equation}
  S = \int_{x_0}^{x_1} \sqrt{1+\left[h'(x)\right]^2} dx\\
\end{equation}

Therefore making the arc length of a parametric curve the following:
\begin{align*}
  S &= \int_{x_0}^{x_1} \sqrt{1+\left[\frac{dy}{dx}\right]^2} dx\\
    &= \int_{x_0}^{x_1} \sqrt{1+\left[\frac{dy/dt}{dx/dt}\right]^2} dx\\
    &= \int_{x_0}^{x_1} \sqrt{\frac{(dx/dt)^2+(dy/dt)^2}{(dx/dt)^2}} dx\\
    &= \int_{x_0}^{x_1}
  \sqrt{\left(\frac{dx}{dt}\right)^2+\left(\frac{dy}{dt}\right)^2} dx\\
    &= \int_{x_0}^{x_1} \sqrt{[f'(t)]^2+[g'(t)]^2} dx\\
\end{align*}

\subsection{Areas of Rotation}
The revolution about the $x$-axis is given:
\begin{equation}
  S=2\pi\int_a^b
  g(t)\sqrt{\left(\frac{dx}{dt}\right)^2+\left(\frac{dy}{dt}\right)^2} dt
\end{equation}

and the area about the $y$-axis is given:
\begin{equation}
  S=2\pi\int_a^b
  f(t)\sqrt{\left(\frac{dx}{dt}\right)^2+\left(\frac{dy}{dt}\right)^2} dt
\end{equation}

\section{Vectors in the Plane}
Vectors are directed line segments that have no origin. Vectors have both
magnitude, and direction, such that any vector is the same no matter where they
start. Vectors are denoted as follows:
$$\vec{v}=\vec{PQ}$$

\subsection{Magnitude}
The magnitude of a vector $\vec{v}$ with the components $\langle x,y\rangle$ may
be calculated as follows:
\begin{equation}
  ||\vec{v}||=\sqrt{x^2+y^2}
\end{equation}

\subsection{Operations}
Let $\vec{u}=\langle u_1,u_2\rangle$ and $\vec{v}=\langle v_1,v_2\rangle$.
\begin{enumerate}
  \item The vector sum of $\vec{u}$ and $\vec{v}$ is $\langle u_1+v_1, u_2+v_2
    \rangle$.
  \item The scalar multiple of $c$ and $\vec{v}$ is $\langle cv_1, cv_2
    \rangle$.
  \item The negative of $\vec{v}$ is $\langle -v_1, -v_2 \rangle$.
  \item The difference of $\vec{u}$ and $\vec{v}$ is $\langle u_1-v_1, u_2-v_2
    \rangle$.
\end{enumerate}

To take the unit vector of a vector $\vec{v}$ in its direction, then the
following is calculated:
\begin{equation}
  \vec{u}=\frac{\vec{v}}{||\vec{v}||}=\frac{1}{||\vec{v}||}\vec{v}
\end{equation}

There are three standard unit vectors in $\mathbb{R}^3$ space:
\begin{description}
  \item[$\hat{i}$] = $\langle 1,0,0 \rangle$
  \item[$\hat{j}$] = $\langle 0,1,0 \rangle$
  \item[$\hat{k}$] = $\langle 0,0,1 \rangle$
\end{description}

\subsection{Space Coordinates and Vectors in Space}
Points in the $\mathbb{R}^2$ plane have coordinates of the form $(x,y)$. Points
in the $\mathbb{R}^3$ space have coordinates of the form $(x,y,z)$.

The distance between two such points takes the following form:
\begin{equation}
  d=\sqrt{(x_2-x_1)^2+(y_2-y_1)^2+(z_2-z_1)^2}
\end{equation}

Vectors in $\mathbb{R}^2$ take the form $\langle x,y,z \rangle$. All of the same
properties of vectors defined in $\mathbb{R}^2$ space apply here as well.

\section{The Dot Product}
The dot product determines information about the angle between two vectors. The
dot producted is calculated between two vectors $\vec{u}=\langle u_1,u_2
\rangle$ and $\vec{v}=\langle v_1,v_2 \rangle$ as follows:

\begin{equation}
  \vec{u} \cdot \vec{v} = u_1v_1 + u_2v_2
\end{equation}

\subsection{The Angle Between Two Vectors}
The dot product gives information about the angle between two non-zero vectors.
The following theorem is presented:
\begin{equation}
  \cos\theta = \frac{\vec{u}\cdot\vec{v}}{||\vec{u}||||\vec{v}||}
\end{equation}

\subsection{Direction Cosines}
The dot product can also be used to determine the angle between a vectors
components in $\mathbb{R}^3$ space and their respective planes of interest. For
example, for the vector $\vec{v} = \langle v_1,v_2,v_3 \rangle$, we can
determine the angle between each planar axis and the components of the vector.

The process is outlined below:
\begin{enumerate}
  \item Take the dot-product of a vector and a unit vector of magnitude $1$ in
    that plane (i.e., $\hat{i}$, $\hat{j}$, or $\hat{k}$).
  \item Apply the definition of the dot-product to determine the direction
    cosine.
\end{enumerate}

\begin{align}
  \cos\alpha &= \frac{v_1}{||\vec{v}||}\\
  \cos\beta  &= \frac{v_2}{||\vec{v}||}\\
  \cos\gamma &= \frac{v_3}{||\vec{v}||}
\end{align}

\subsection{Projections}
To project $\vec{u}$ onto $\vec{v}$ is to take the length of $\vec{u}$ in the
direction of $\vec{v}$. The notation is as follows below:

\begin{equation}
  \text{proj}_{\vec{v}}\vec{u}=
  \left(\frac{\vec{u}\cdot\vec{v}}{||\vec{v}||^2}\right)\vec{v}
\end{equation}

\subsubsection{Work}
\begin{align}
  W &= ||\text{proj}_{\vec{PQ}}\vec{F}||||\vec{PQ}|| \\
    &= \vec{F} \cdot \vec{PQ}
\end{align}

\section{The Cross Product}
Let $\vec{u}=\langle u_1,u_2,u_3 \rangle$ and $\vec{v}=\langle v_1,v_2,v_3
\rangle$. The cross product of $\vec{u}$ and $\vec{v}$ is said to be:
\begin{equation}
  \vec{u}\times\vec{v} = (u_2v_3-u_3v_2)\hat{i} - (u_1v_3-u_3v_1)\hat{j} +
  (u_1v_2-u_2v_1)\hat{k}
\end{equation}

Another way to calculate the cross product is with matricies:

\begin{equation}
  \begin{aligned}
    \vec{u}\times\vec{v} &= \begin{vmatrix}
      \hat{i} & \hat{j} & \hat{k} \\
      u_1     & u_2     & u_3 \\
      v_1     & v_2     & v_3
    \end{vmatrix} \\
  &= \begin{vmatrix}
    u_2 & u_3 \\
    v_2 & v_3 \\
  \end{vmatrix}\hat{i} -
  \begin{vmatrix}
    u_1 & u_3 \\
    v_1 & v_3 \\
  \end{vmatrix}\hat{j} +
  \begin{vmatrix}
    u_1 & u_2 \\
    v_1 & v_2 \\
  \end{vmatrix}\hat{k}\\
  &= (u_2v_3-u_3v_2)\hat{i} - (u_1v_3-u_3v_1)\hat{j} + (u_1v_2-u_2v_1)\hat{k}
  \end{aligned}
\end{equation}

\subsection{Algebraic Properties}
\begin{enumerate}
  \item $\vec{u}\times\vec{v}=-(\vec{v}\times\vec{u})$
  \item
    $\vec{u}\times(\vec{v}+\vec{w})=(\vec{u}\times\vec{v})+
    (\vec{u}\times\vec{w})$
  \item
    $c(\vec{u}\times\vec{v})=(c\vec{u})\times\vec{v}=\vec{u}\times(c\vec{v})$
  \item $\vec{u}\times0=0\times\vec{u}=0$
  \item $\vec{u}\times\vec{u}=0$
  \item $\vec{u}\dot(\vec{v}\times\vec{w}=(\vec{u}\times\vec{v})\cdot\vec{w}$
\end{enumerate}

\subsection{Geometric Properties}
\begin{enumerate}
  \item $\vec{u}\times\vec{v}$ is orthagonal to both $\vec{u}$ and $\vec{v}$
  \item $||\vec{u}\times\vec{v}||=||\vec{u}||||\vec{v}||\sin\theta$
  \item $\vec{u}\times\vec{v}=0$ only if $\vec{u}=c\vec{v}$
  \item $||\vec{u}\times\vec{v}||$ is the area of a parallelogram having
    $\vec{u}$ and $\vec{v}$ as adjacent sides.
\end{enumerate}

\subsection{The Triple Scalar Product}
\begin{equation}
  \vec{u}\cdot(\vec{v}\times\vec{w})=\begin{vmatrix}
    u_1 & u_2 & u_3 \\
    v_1 & v_2 & v_3 \\
    w_1 & w_2 & w_3
  \end{vmatrix}
\end{equation}

\subsubsection{Geometric Properties}
The volume of a parallelpiped with significant edges $\vec{u}$, $\vec{v}$, and
$\vec{w}$ is defined as:
\begin{equation}
  \begin{aligned}
    V &= |\vec{u}\cdot(\vec{v}\times\vec{w})| \\
      &= ||\text{proj}_{\vec{v}\times\vec{w}}||||\vec{v}\times\vec{w}|| \\
      &= \left|\frac
        {\vec{u}\cdot(\vec{v}\times\vec{w})}
        {||\vec{v}\times\vec{w}||}\right|
        ||\vec{v}\times\vec{w}|| \\
      &= |\vec{u}\cdot(\vec{v}\times\vec{w})|
  \end{aligned}
\end{equation}

\section{Lines and Planes in Space}
\subsection{Lines}
Given a line containing the point $P(x_1,y_1,z_1)$ in space parallel to the
vector $\vec{v}=\langle a,b,c \rangle$, the vector $\vec{v}$ is the direction
vector and the numbers $a$, $b$, and $c$ are direction numbers. One can surmise
that a line in space $L$ contains all points $Q(x,y,z)$ for which
$\vec{PQ}=c\vec{v}$.

\begin{equation}
  \begin{aligned}
    \vec{PQ} &= \langle x-x_1, y-y_1, z-z_1 \rangle \\
             &= \langle at, bt, ct \rangle \\
             &= t\vec{v}
  \end{aligned}
\end{equation}

The following parametric equations are generated:
\begin{align}
  x=x_1+at \\
  y=y_1+at \\
  z=z_1+at
\end{align}

and the symmetric equation of the line can be generated by eliminating the
parameter:

\begin{equation}
  \frac{x-x_1}{a} = \frac{y-y_1}{b} = \frac{z-z_1}{c}
\end{equation}

\subsection{Planes}
Consider a plane in space containing the point $P(x_1,y_1,z_1)$ and
$Q(x_2,y_2,z_2)$. There is some vector in the plane, therefore, $\vec{v}=\langle
(x_2-x_1,y_2-y_1,x_2-z-1 \rangle$, and some other vector $\vec{n}$ such that
$\vec{v}\cdot\vec{n}=0$. Let $\vec{n}=\langle a,b,c \rangle$.

It can be said that:
\begin{equation}
  \begin{aligned}
    \vec{n}\cdot\vec{PQ} &= 0\\
    \langle a,b,c \rangle \cdot \langle x-x_1, y-y_1, z-z_1 \rangle &= 0\\
    a(x-x_1)+b(y-y_1)+c(z-z_1) &= 0\\
    ax+by+cz+d &= 0
  \end{aligned}
\end{equation}

To generate the vector $\vec{n}$, it is useful to generate two vectors in the
plane $\vec{u}$ and $\vec{v}$ and then take their cross product to obtain
$\vec{n}$ such that $\vec{u}\times\vec{v}=\vec{n}$.

The dot-product can be used to determine the angle between two planes by using
their normal vectors $\vec{n_1}$ and $\vec{n_2}$.
\begin{equation}
  \cos\theta=\frac{|\vec{n_1}\cdot\vec{n_2}|}{||\vec{n_1}||||\vec{n_2}||}
\end{equation}

\subsubsection{Distance between a Point and a Plane}
The distance $D$ between a point $Q(x_0,y_0,z_0)$ (not in the plane) and $P$ (in
the plane with the direction numbers $A$, $B$, $C$, and $D$) is:
\begin{equation}
  \begin{aligned}
    D &= ||\text{proj}_{\vec{n}}\vec{PQ}|| \\
      &= \frac{\vec{PQ}\cdot\vec{n}}{||\vec{n}||} \\
      &= \frac{|ax_0+by_0+cz_0+d|}{\sqrt{a^2+b^2+c^2}}
  \end{aligned}
\end{equation}

\subsubsection{Distance between a Point and a Line}
The distance $D$ between a point $Q$ and a line in space containing the point
$P$ is:
\begin{equation}
  D = \frac{||\vec{PQ}\times\vec{u}||}{||\vec{u}||}
\end{equation}

\section{Vectored-Valued Functions}
Vectored valued functions are functions that produced vectors ($\langle x,y,z
\rangle$ in $\mathbb{R}^3$ space, $\langle x,y \rangle$ in $\mathbb{R}^2$ space).

Vectored valued functions are denoted as follows:

\begin{equation}
  \vec{r}(t) = \langle \vec{f}(t), \vec{g}(t), \vec{h}(t) \rangle
\end{equation}

These functions are drawn as normal curves, such that each point on the curve
$P(x,y)$ represents a vector $\vec{v} = \langle x,y \rangle$. Just like normal
parametric curves, they have direction or orientation.

The limits of these functions may be taken as follows:
\begin{equation}
  \lim_{x\to{a}} \vec{r}(t) =
    \left[\lim_{x\to{a}}\vec{f}(t)\right]\hat{i} +
    \left[\lim_{x\to{a}}\vec{g}(t)\right]\hat{j} +
    \left[\lim_{x\to{a}}\vec{h}(t)\right]\hat{k}
\end{equation}

\section{Calculus of Vectored-Valued Functions}
\subsection{Differentiation}
The derivative of a vectored-valued function $\vec{r}(t)$ is given as:
\begin{equation}
  \vec{r}'(t)=\lim_{\Delta{t}\to{0}}
    \frac{\vec{r}(t+\Delta{t})-\vec{r}(t)}{\Delta{t}}
\end{equation}

Such that:
\begin{equation}
  \vec{r}'(t) = \frac{d}{dt}\vec{f}(t) +
                \frac{d}{dt}\vec{g}(t) +
                \frac{d}{dt}\vec{h}(t)
\end{equation}

\subsection{Properties}
\begin{enumerate}
  \item $$\frac{d}{dt}[\vec{r}(t)\cdot\vec{u}(t)] = \vec{r}(t)\cdot\vec{u}'(t) +
                                                    \vec{u}(t)\cdot\vec{r}'(t)$$
  \item $$\frac{d}{dt}[\vec{r}(t)\times\vec{u}(t)]=\vec{r}(t)\times\vec{u}'(t) +
                                                   \vec{u}(t)\times\vec{r}'(t)$$
\end{enumerate}

\subsection{Integration}
The integral of a vectored-valued function $\vec{r}(t)$ is given as: (note, this
applies to vector-valued functions in $\mathbb{R}^2$ and $\mathbb{R}^3$ for both
definite and indefinite integrals)
\begin{equation}
  \int \vec{r}(t) dt = \left(\int \vec{f}(t) dt\right)\hat{i} +
                       \left(\int \vec{g}(t) dt\right)\hat{j} +
                       \left(\int \vec{h}(t) dt\right)\hat{k}
\end{equation}

\section{Velocity \& Acceleration}
Let $\vec{a}(t)$, $\vec{v}(t)$ and $\vec{r}(t)$ represent the acceleration,
velocity, and position of an object in $\mathbb{R}^2$ or $\mathbb{R}^3$
respectively.
\begin{equation}
  \vec{a}(t) = \frac{d}{dt}\left[\vec{v}(t)\right]
             = \frac{d^2}{dt^2}\left[\vec{r}(t)\right]
\end{equation}


\subsection{Continous time with Lie algebra}

We use \(X=iH\), what are the implications of this compared to other choices?

Lie algebras with \(n\times x\)

This loops back? multiple dimensions, infinite, so maybe not?

With continuous time we do not have a single operator to describe movements. There is always one smaller.

With continous time there must be either a single state, or an uncountably infinite number of states.

\(U=M_n^n\)

\(U=(I+\dfrac{1}{n}G_n)^n\)

\(U=\lim_{n\rightarrow \infty }(I+\dfrac{1}{n}G)^n\)

Now:

\(UU^*=I\)

\((I+\dfrac{1}{n}G)(I+\dfrac{1}{n}G)^*=I\)

\((I+\dfrac{1}{n}G)(I+\dfrac{1}{n}G^*)=I\)

\(G=-G^*\)

\(G=iH\)

\(iH=-(iH)^*\)

\(H=H^*\)

\(H\) is Hermitian

\(U=\lim_{n\rightarrow \infty }(I+\dfrac{1}{n}iH)^n\)

This isn't quite right, need defined for different time jumps.


\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\newtheorem{problem}{Problem}
\newtheorem{lemma}{Lemma}
\usepackage{harpoon}%
\usepackage{float}
\usepackage{verbatim}

\title{Notes on Trilinear Aggregation}
\author{Jason Yang}
\date{August 2021}

\begin{document}

\maketitle

\section{Introduction}

This paper outlines the notes I have taken while reading the papers ``Strassen's Algorithm is not Optimal / Trilinear Technique of Aggregating, Uniting and Canceling for / Constructing Fast Algorithms for Matrix Operations" (Pan) \begin{verbatim} https://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=4567976 \end{verbatim} and "On Practical Algorithms for Accelerated Matrix Multiplication" (Laderman, Pan, Sha) \begin{verbatim} https://www.sciencedirect.com/science/article/pii/002437959290393O \end{verbatim}. These two papers show what is called the \textit{trilinear aggregation} technique of multiplying two moderately-sized matrices together by using as few multiplications as possible. I think they are especially interesting because they aren't well known and aren't mentioned often by other researchers, since more attention has been given to the asymptotically fastest matrix multiplication algorithms. These algorithms are very theoretically interesting, but are incredibly complicated and are only faster than naive matrix multiplication for absurdly large matrices. Therefore, I believe trilinear aggregation deserves more attention if we want to make new fast matrix multiplication algorithms that are actually usable in the real world.

\section{Definitions}

We have matrices $A=[A_{i,j}]_{i,j}$ and $B=[B_{j,k}]_{j,k}$ of size $M\times K$ and $K\times N$ respectively and want to compute the matrix product $C=AB:=[\sum_{j} A_{i,j}B_{j,k}]_{i,k}$ using as few multiplications between elements of $A$ and $B$ as possible. Here, we disregard scalar multiplications, e.g. using the $2A_{i,j}$ has no cost. We also do not care how many additions we make between elements of $A$ and $B$.

The reason we care about reducing the number of multiplications is that the elements of $A$ and $B$ don't have to be just numbers. In particular, they can also be smaller matrices, meaning any procedure for multiplying the elements of $A$ and $B$ immediately yields a divide-and-conquer algorithm for multiplying arbitrary matrices of any size (provided there are base case algorithms for small sizes). It can be shown that if we have way of multiplying a $M\times K$ matrix with a $K\times N$ matrix using $R$ multiplications, then we have a $O(N^{3\log_{MKN} R})$-time algorithm for multiplying two $N\times N$ matrices together. Additions and scalar multiplications become insignificant to the asymptotic time complexity.

The naive algorithm, which comes directly from the definition of the matrix product, requires $MKN$ multiplications and computes two $N\times N$ matrices in $O(N^3)$ time. For $(M,K,N)=(2,2,2)$, however, V. Strassen found a clever algorithm using only 7 multiplications instead of the expected $2*2*2=8$ multiplications. This yielded the first ever sub $O(N^3)$-time algorithm for multiplying two $N\times N$ matrices together, as it runs in $O(N^{log_2 7})=O(N^{\sim 2.807})$ time.

\section{Tensor Representation of Matrix Multiplication}

What is the general form of an algorithm multiplying matrices $A$ and $B$ with few multiplications? Since the matrix product $AB$ only involves terms of the form $ab$ for some element $a$ in $A$ and some element in $B$, it does not make sense to have triple products of the elements of $A$ and $B$, nor to have elements of $A$ and $B$ by themselves, only multiplied with scalars. Thus, all multiplications are of the form $(\sum_{ij}\alpha_{ij}A_{ij})*(\sum_{jk}\beta_{jk}B_{jk})$, i.e. a linear combination of the elements of $A$ multiplied by a linear combination of the elements of $B$.

If we use $R$ multiplications, we can represent the $r$-th product as $P_r=(\sum_{ij}\alpha_{rij}A_{ij})*(\sum_{jk}\beta_{rjk}B_{jk})$, where $\alpha_{rij},\beta_{rjk}$ are scalar coefficients. Then the $(j,k)$-th element of the matrix product $C_{jk}=(AB)_{jk}=\sum_{j}A_{ij}B_{jk}$ must be obtainable as a linear combination of the products $P_r$, i.e. $C_{jk}=\sum_{r}\gamma_{rki}P_{r}$ for coefficients $\gamma_{rki}$ (we use $\gamma_{rki}$ and not $\gamma_{rik})$ because that way the resulting matrix multiplication tensor we will define shortly will have more symmetry). Plugging in the definitions of $C_{jk}$ and $P_r$ yields $\sum_{j}A_{ij}B_{jk}=\sum_{r}\gamma_{rki}(\sum_{ij}\alpha_{rij}A_{ij})*(\sum_{jk}\beta_{rjk}B_{jk})$. If we want the coefficients of $\alpha,\beta,\gamma$ to make this equation valid for any matrices $A,B$, then we obtain the so-called \textit{Brent equations}:

\[\sum_{r=0}^{R-1} \alpha_{ri_0j_0}\beta_{rj_1k_1}\gamma_{rk_2i_2}=\begin{cases}
1 & j_0=j_1 \wedge k_1=k_2 \wedge i_2=i_0 \\
0 & \texttt{else} \\
\end{cases}\]

\textbf{Any set of coefficients of $\alpha,\beta,\gamma$ that satisfies this system of equations describes a valid algorithm for multiplying a $M\times K$ matrix with a $K\times N$ matrix using only $R$ multiplications between matrix elements}.

We can rewrite this system of equations as a tensor equation. A \textit{tensor} for our purposes is a $n$-dimensional array $A_{i_0,\dots i_{n-1}}$. Additionally, define the \textit{outer product} of two tensors $A,B$ of dimensions $n,m$ respectively to be the $(n+m)$-dimensional tensor $A\times B$ s.t. $(A\times B)_{i_0,\dots i_{n-1},j_0,\dots j_{m-1}}=A_{i_0,\dots i_{n-1}}B_{j_0,\dots j_{m-1}}$. Finally, define the \textit{matrix multiplication tensor} $\mathcal{M}(M,K,N)$ to be the $M\times K\times K\times N\times N\times M$ tensor s.t. the element at coordinate $(i_0,j_0,j_1,k_1,k_2,i_2)$ is 1 if $j_0=j_1 \wedge k_1=k_2 \wedge i_2=i_0$ and 0 otherwise. Then the Brent equations above are equivalent to the following tensor equation:

\[\sum_{r=0}^{R-1} \alpha_r\times\beta_r\times\gamma_r=\mathcal{M}(M,K,N),\]

where $\alpha_r, \beta_r, \gamma_r$ are the $r$ matrices of $\alpha,\beta,\gamma$ respectively. The minimum $R$ such that the equation can be satisfied is called the \textit{rank} of the tensor $\mathcal{M}(M,K,N)$. Thus, finding a fast matrix multiplication algorithm is equivalent to finding a low-rank decomposition of $\mathcal{M}(M,K,N)$.

\section{Trilinear Aggregation}
In this section we show Pan's technique of trilinear aggregation, which yielded the first matrix multiplication algorithm asymptotically faster than Strassen's algorithm. We will only consider the case $M=K=N$ (i.e. we will only consider multiplying two $N\times N$ matrices together).

Let $\mathcal{M}(N)=\mathcal{M}(N,N,N)$, $[N]=\{0,\dots N-1\}$, $[N]^3=\{(i,j,k)|i,j,k\in [N]\}$, and $E_{i,j}$ be the $N\times N$ matrix with its element at $(i,j)$ equal to 1 and all other elements equal to 0. Also, for brevity, we will omit the $\times$ symbol when evaluating the outer product between two tensors. Finally, we will refer to a \textit{term} as a set of three matrices that have been combined using the outer product.

The matrix multiplication tensor $\mathcal{M}(N)$ has a trivial $N^3$-rank decomposition:

\[\mathcal{M}(N)=\sum_{(i,j,k)\in [N]^3}E_{i,j}E_{j,k}E_{k,i}.\]

Notice that we can define a bijection $(i,j,k)\Longleftrightarrow E_{i,j}E_{j,k}E_{k,i}$ between the elements of $[N]^3$ and the terms in the trivial decomposition.

Pan's technique starts by organizing the terms of the trivial decomposition into groups of 3 as follows:

\[\mathcal{M}(N)=(\sum_{(i,j,k)\in S}E_{i,j}E_{j,k}E_{k,i}+E_{j,k}E_{k,i}E_{i,j}+E_{k,i}E_{i,j}E_{j,k})+(\sum_{i\in [N]} E_{i,i}E_{i,i}E_{i,i}).\]

Here we define a set $S\in [N]^3$ s.t. $\cup_{(i,j,k)\in S}\{(i,j,k),(j,k,i),(k,i,j)\}=[N]^3\setminus\{(i,i,i)|i\in [N]\}$ and the sets $S$, $\{(j,k,i)|(i,j,k)\in S\}$, and $\{(k,i,j)|(i,j,k)\in S\}$ are mutually disjoint. Thus, $|S|=\frac{N^3-N}{3}$. The terms $E_{i,i}E_{i,i}E_{i,i}$ must be treated separately.

Next, we replace $\sum_{(i,j,k)\in S}E_{i,j}E_{j,k}E_{k,i}+E_{j,k}E_{k,i}E_{i,j}+E_{k,i}E_{i,j}E_{j,k}$ with $\sum_{i,j,k}(E_{i,j}+E_{j,k}+E_{k,i})(E_{j,k}+E_{k,i}+E_{i,j})(E_{k,i}+E_{i,j}+E_{j,k})$. With this method, we generate all the terms $E_{i,j}E_{j,k}E_{k,i}, E_{j,k}E_{k,i}E_{i,j}, E_{k,i}E_{i,j}E_{j,k}$ using only $\frac{N^3-N}{3}$ terms instead of $N^3-N$ terms, a big improvement. However, we also generate several unwanted terms in the process.

The final step is to remove these unwanted terms. We can use the distributive law to our advantage to remove most of these terms with only $O(N^2)$ terms. For example, consider removing terms of the form $E_{i,j}E_{i,j}E_{j,k}$: instead of calculating $\sum_{(i,j,k)\in S} E_{i,j}E_{i,j}E_{j,k}$ naively, we can rewrite it as $\sum_{i,j\in [N]}E_{i,j}E_{i,j}(\sum_{k|(i,j,k)\in S}E_{j,k})$, which only takes $N^2$ terms instead of $\frac{N^3-N}{3}$. We will call such terms \textit{intermediate terms}, as together they can be removed using only $O(N^2)$ terms. In general, any $E_aE_bE_c$ where each $a,b,c$ represents a pair of indices is an intermediate term if $a,b,c$ are not all mutually distinct. We will initially ignore the details of actually removing the intermediate terms and talk about them later. For now, we have the following:

\begin{comment}
We will define the sets $S_{IJ},S_{JK},S_{KI}$ to be $\{(i,j)|(i,j,k)\in S\},\{(j,k)|(i,j,k)\in S\},\{(k,i)|(i,j,k)\in S\}$.
\end{comment}

\[\sum_{(i,j,k)\in S}E_{i,j}E_{j,k}E_{k,i}+E_{j,k}E_{k,i}E_{i,j}+E_{k,i}E_{i,j}E_{j,k}\]
\begin{comment}
\[=\sum_{(i,j,k)\in S}\Big[(E_{i,j}+E_{j,k}+E_{k,i})(E_{j,k}+E_{k,i}+E_{i,j})(E_{k,i}+E_{i,j}+E_{j,k})\]
\[-E_{i,j}E_{i,j}(E_{k,i}+E_{i,j}+E_{j,k})-E_{j,k}E_{j,k}(E_{k,i}+E_{i,j}+E_{j,k})-E_{k,i}E_{k,i}(E_{k,i}+E_{i,j}+E_{j,k})\]
\[-E_{i,j}(E_{j,k}+E_{k,i}E_{i,j}-E_{j,k}(E_{i,j}+E_{k,i})E_{j,k}-E_{k,i}(E_{i,j}+E_{j,k})E_{k,i}\]
\[-(E_{j,k}+E_{k,i})E_{i,j}E_{i,j}-(E_{i,j}+E_{k,i})E_{j,k}E_{j,k}-(E_{i,j}+E_{j,k})E_{k,i}E_{k,i}\]
\[-E_{i,j}E_{k,i}E_{j,k}-E_{j,k}E_{i,j}E_{k,i}-E_{k,i}E_{j,k}E_{i,j}\Big]\]
\end{comment}

\[=\sum_{(i,j,k)\in S}(E_{i,j}+E_{j,k}+E_{k,i})(E_{j,k}+E_{k,i}+E_{i,j})(E_{k,i}+E_{i,j}+E_{j,k})\]
\begin{comment}
\[-\sum_{(i,j)\in S_{IJ}}E_{i,j}E_{i,j}(\sum_k^*E_{k,i}+E_{i,j}+E_{j,k})\]
\[-\sum_{(j,k)\in S_{JK}}E_{j,k}E_{j,k}(\sum_i^*E_{k,i}+E_{i,j}+E_{j,k})\]
\[-\sum_{(k,i)\in S_{KI}}E_{k,i}E_{k,i}(\sum_j^*E_{k,i}+E_{i,j}+E_{j,k})\]
\[-\sum_{(i,j)\in S_{IJ}}E_{i,j}(\sum_k^*E_{j,k}+E_{k,i})E_{i,j}\]
\[-\sum_{(j,k)\in S_{JK}}E_{j,k}(\sum_i^*E_{i,j}+E_{k,i})E_{j,k}\]
\[-\sum_{(k,i)\in S_{KI}}E_{k,i}(\sum_j^*E_{i,j}+E_{j,k})E_{k,i}\]
\[-\sum_{(i,j)\in S_{IJ}}(\sum_k^*E_{j,k}+E_{k,i})E_{i,j}E_{i,j}\]
\[-\sum_{(j,k)\in S_{JK}}(\sum_i^*E_{i,j}+E_{k,i})E_{j,k}E_{j,k}\]
\[-\sum_{(k,i)\in S_{KI}}(\sum_j^*E_{i,j}+E_{j,k})E_{k,i}E_{k,i}\]
\end{comment}
\[-\Big[ O(N^2) \texttt{many terms}\Big]\]
\[-\Big(\sum_{(i,j,k)\in S}E_{i,j}E_{k,i}E_{j,k}+E_{j,k}E_{i,j}E_{k,i}+E_{k,i}E_{j,k}E_{i,j}\Big),\]

\begin{comment}
where $\sum_i^*,\sum_j^*,\sum_K^*$ are short for $\sum_{i|(i,j,k)\in S},\sum_{j|(i,j,k)\in S},\sum_{k|(i,j,k)\in S}$ respectively.
\end{comment}

We will call the terms $(E_{i,j}+E_{j,k}+E_{k,i})(E_{j,k}+E_{k,i}+E_{i,j})(E_{k,i}+E_{i,j}+E_{j,k})$ the \textit{aggregation terms} and the terms $E_{i,j}E_{k,i}E_{j,k}, E_{j,k}E_{i,j}E_{k,i}, E_{k,i}E_{j,k}E_{i,j}$ \textit{unacceptable terms}, as they cannot be easily evaluated with only $O(N^2)$ terms.

We can summarize the above long equation with an \textit{aggregation table}:

\begin{table}[H]
    \centering
    \begin{tabular}{c|c|c}
        $ij$ & $jk$ & $ki$ \\
        $jk$ & $ki$ & $ij$ \\
        $ki$ & $ij$ & $jk$ \\
    \end{tabular}
    \label{group1}
    \caption{}
\end{table}

In the aggregation table, each entry represents a matrix $E_{i,j}$; the letter $E$ has simply been omitted for brevity. Then our target terms correspond to the sum of the products of the rows, our aggregation term corresponds to the product of the sum of the columns, and our unacceptable terms come from the lists of coordinates $[(0,0),(1,1),(2,2]$, $[(1,0),(2,1),(0,2)]$, and $[(2,0),(0,1),(1,2)]$. In this specific table, the unnecceptable terms can be written as $ijkijk,jkijki,kijij$.

To eliminate the unacceptable terms, Pan uses a clever trick: expand all matrices $E_{i,j}$ to size $2N\times 2N$ and evaluate the tensor $\mathcal{M}(2N)$ instead of $\mathcal{M}(N)$. To retain the restriction $(i,j,k)\in S$, we can represent the trivial decomposition of $\mathcal{M}(2N)$ as follows:

\[\sum_{a,b,c\in [2]}\Big[\Big(\sum_{(i,j,k)\in S}E_{i+aN,j+bN}E_{j+bN,k+cN}E_{k+cN,i+aN}\]\[+E_{j+bN,k+cN}E_{k+cN,i+aN}E_{i+aN,j+bN}\]\[+E_{k+cN,i+aN}E_{i+aN,j+bN}E_{j+bN,k+cN}\Big)\]\[+\Big(\sum_{i\in [N]} E_{i+aN,i+bN}E_{i+bN,i+cN}E_{i+cN,i+aN}\Big)\Big].\]

Now, the trilinear aggregation technique involves organizing the 24 terms $E_{i+aN,j+bN}E_{j+bN,k+cN}E_{k+cN,i+aN}$, $E_{j+bN,k+cN}E_{k+cN,i+aN}E_{i+aN,j+bN}$, and\\ $E_{k+cN,i+aN}E_{i+aN,j+bN}E_{j+bN,k+cN} \forall a,b,c\in [2]$ and for fixed $i,j,k$ into 8 groups of 3, where each group is replaced with an aggregation term and a set of intermediate terms, such that the unacceptable terms from each of the groups cancel each other out.

To accomplish this, let us abbreviate the expressions $i+N,j+N,k+N$ as $\bar{i},\bar{j},\bar{k}$ respectively. The first group is described by Table 1 above and generates the unacceptable terms $E_{i,j}E_{k,i}E_{j,k},E_{j,k}E_{i,j}E_{k,i},E_{k,i}E_{j,k}E_{i,j}$, which we will abbreviate as $ijkijk,jkijki,kijkij$. Let's try removing $ijkijk$ with our second group. We will need to add a negative sign:

\begin{table}[H]
    \centering
    \begin{tabular}{c|c|c}
        $-ij$ & $j?$ & $-?i$ \\
        $?k$ & $ki$ & $i?$ \\
        $k?$ & $?j$ & $jk$ \\
    \end{tabular}
\end{table}

In the above table, we already know partial information about the elements not on the main diagonal, since each row must form a valid target term. For example, $ij\bar{j}kki$ is invalid. In general, any target term must be of the form $abbcca$, where each occurrence of the same letter represents the same index.

We also need to add a second negative sign in the first row to counteract the initial negative sign we added to cancel out $ijkijk$. To match Pan's solution, we arbitrarily place this negative sign at the rightmost column. Finally, we must have each of the rows evaluate to new target terms we have not already evaluated, e.g. we cannot set the first row of Table 2 to $-ij|jk|-ki$ since that would simply create the target term $ijjkki$ that we already got from Table 1. This constraint forces our new table to be:

\begin{table}[H]
    \centering
    \begin{tabular}{c|c|c}
        $-ij$ & $j\bar{k}$ & $-\bar{k}i$ \\
        $\bar{j}k$ & $ki$ & $i\bar{j}$ \\
        $k\bar{i}$ & $\bar{i}j$ & $jk$ \\
    \end{tabular}
    \caption{}
\end{table}

What this table means is that we calculate the aggregation terms $\sum_{(i,j,k)\in S}(-E_{i,j}+E_{\bar{j},k}+E_{k,\bar{i}})(E_{j,\bar{k}}+E_{k,i}+E_{\bar{i},j})(-E_{\bar{k},j}+E_{i,\bar{j}}+E_{j,k})$ and remove the resulting intermediate terms.

We continue in this fashion, cancelling out $jkijki$ with Table 3 and $kijkij$ with Table 4:

\begin{table}[H]
    \centering
    \begin{tabular}{c|c|c}
        $i\bar{j}$ & $\bar{j}k$ & $ki$ \\
        $-jk$ & $k\bar{i}$ & $-\bar{i}j$ \\
        $\bar{k}i$ & $ij$ & $j\bar{k}$ \\
    \end{tabular}
    \caption{}
\end{table}

\begin{table}[H]
    \centering
    \begin{tabular}{c|c|c}
        $\bar{i}j$ & $jk$ & $k\bar{i}$ \\
        $j\bar{k}$ & $\bar{k}i$ & $ij$ \\
        $-ki$ & $i\bar{j}$ & $-\bar{j}k$ \\
    \end{tabular}
    \caption{}
\end{table}

Now, we have cancelled all unacceptable terms generated by Table 1, but we have also created new unacceptable terms $i\bar{j}k\bar{i}j\bar{k}$,$j\bar{k}i\bar{j}k\bar{i}$,$k\bar{i}j\bar{k}i\bar{j}$,$-\bar{i}j\bar{k}i\bar{j}k$,$-\bar{j}k\bar{i}j\bar{k}i$,\\$-\bar{k}i\bar{j}k\bar{i}j$ from Tables 2-4. To eliminate these terms, we simply duplicate Tables 1-4 and swap the bar variables with no-bar variables; the unacceptable terms generated from these new tables will perfectly cancel out our current unacceptable terms:

\begin{table}[H]
    \centering
    \begin{tabular}{c|c|c}
        $\bar{i}\bar{j}$ & $\bar{j}\bar{k}$ & $\bar{k}\bar{i}$ \\
        $\bar{j}\bar{k}$ & $\bar{k}\bar{i}$ & $\bar{i}\bar{j}$ \\
        $\bar{k}\bar{i}$ & $\bar{i}\bar{j}$ & $\bar{j}\bar{k}$ \\
    \end{tabular}
    \caption{}
\end{table}

\begin{table}[H]
    \centering
    \begin{tabular}{c|c|c}
        $-i\bar{j}$ & $\bar{j}k$ & $-k\bar{i}$ \\
        $j\bar{k}$ & $\bar{k}\bar{i}$ & $\bar{i}j$ \\
        $\bar{k}i$ & $i\bar{j}$ & $\bar{j}\bar{k}$ \\
    \end{tabular}
    \caption{}
\end{table}

\begin{table}[H]
    \centering
    \begin{tabular}{c|c|c}
        $\bar{i}j$ & $j\bar{k}$ & $\bar{k}\bar{i}$ \\
        $-\bar{j}\bar{k}$ & $\bar{k}i$ & $-i\bar{j}$ \\
        $k\bar{i}$ & $\bar{i}\bar{j}$ & $\bar{j}k$ \\
    \end{tabular}
    \caption{}
\end{table}

\begin{table}[H]
    \centering
    \begin{tabular}{c|c|c}
        $i\bar{j}$ & $\bar{j}\bar{k}$ & $\bar{k}i$ \\
        $\bar{j}k$ & $k\bar{i}$ & $\bar{i}\bar{j}$ \\
        $-\bar{k}\bar{i}$ & $\bar{i}j$ & $-j\bar{k}$ \\
    \end{tabular}
    \caption{}
\end{table}

Thus, we have a way of decomposing the tensor $\mathcal{M}(2N)$ into $8(\frac{N^3-N}{3})+O(N^2)+8N$ terms instead of $8N^3$ terms with the trivial decomposition. The $8N$ terms from calculating $\sum_{a,b,c\in [2]}\sum_{i\in [N]} E_{i+aN,i+bN}E_{i+bN,i+cN}E_{i+cN,i+aN}$ can be improved to $7N$ terms using Strassen's algorithm.

\end{document}


\hypertarget{classnumpp_1_1differentiation_1_1symbolic_1_1power}{}\section{numpp\+:\+:differentiation\+:\+:symbolic\+:\+:power$<$ Left, Exp $>$ Class Template Reference}
\label{classnumpp_1_1differentiation_1_1symbolic_1_1power}\index{numpp\+::differentiation\+::symbolic\+::power$<$ Left, Exp $>$@{numpp\+::differentiation\+::symbolic\+::power$<$ Left, Exp $>$}}
\subsection*{Public Types}
\begin{DoxyCompactItemize}
\item
\mbox{\Hypertarget{classnumpp_1_1differentiation_1_1symbolic_1_1power_aba34fd92a6784601b20d66413423802b}\label{classnumpp_1_1differentiation_1_1symbolic_1_1power_aba34fd92a6784601b20d66413423802b}}
{\footnotesize template$<$std\+::size\+\_\+t Active$>$ }\\using {\bfseries derivative} = simplify\+\_\+multiplication$<$ \hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1multiply}{multiply}$<$ \hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1constant}{constant}$<$ Exp $>$, \hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1power}{power}$<$ Left, Exp-\/1 $>$ $>$, typename Left\+::template derivative$<$ Active $>$ $>$
\end{DoxyCompactItemize}
\subsection*{Static Public Member Functions}
\begin{DoxyCompactItemize}
\item
\mbox{\Hypertarget{classnumpp_1_1differentiation_1_1symbolic_1_1power_a02f035c5198288fa0f22c48655574904}\label{classnumpp_1_1differentiation_1_1symbolic_1_1power_a02f035c5198288fa0f22c48655574904}}
static C\+O\+N\+S\+T\+E\+X\+PR auto {\bfseries calculate} (auto \&\&values)
\end{DoxyCompactItemize}

The documentation for this class was generated from the following file\+:\begin{DoxyCompactItemize}
\item
differentiation/symbolic/arithmetic.\+hpp\end{DoxyCompactItemize}


\section{Model Optimization}
\label{sec:optimizerStrategies}

When analyzing the range of values obtainable by a model, frequently a key question is ``what set of
parameters result in the best response value?''  To answer this question, RAVEN uses the \xmlNode{Optimizer},
a powerful sampler-like entity that searches the input space to find minimum or maximum values of a response.

In the remainder of this section, we will explore how to use the optimizer using a simple analytic problem,
with a two-dimensional input space and single response of interest.  After getting used to running with the
optimizer, we will add increasing complexity, including changing adaptive step sizes, initial conditions,
parallel trajectories, input space subdivision, input space constraints, and response constraints.

To demonstrate the operation of the Optimizer entities in RAVEN, the model we consider is the Beale function,
which is documented in the analytic tests for RAVEN and replicated here:

\begin{itemize}
  \item Function: $f(x,y) = (1.5-x+xy)^2+(2.25-x+xy^2)^2+(2.625-x+xy^3)^2$
  \item Domain: $-4.5 \leq x,y \leq 4.5$
  \item Global Minimum: $f(3,0.5)=0$
\end{itemize}

The two inputs are the variables $x$ and $y$, and the response is a value we'll assign to $ans$, short for
``answer''.  The model is an external model in RAVEN, and can be found at
\begin{verbatim}
  raven/tests/framework/AnalyticModes/optimizing/beale.py.
\end{verbatim}
The function's values are distributed as in Fig. \ref{fig:beale}, with red indicating high values
and blue indicating low values.
\begin{figure}[h!]
  \centering
  \includegraphics[scale=0.7]{../../tests/framework/user_guide/optimizing/Beale_grid.png}
  \caption{Plot of Beale's function for Optimization}
  \label{fig:beale}
\end{figure}
The objective is to minimize the function.

Note that throughout this example we use the SPSA optimizer by way of demonstration, since it is the first
advanced algorithm for optimization included in RAVEN; many of the options and parameters apply to other
optimizers, and details can be found in the RAVEN user manual.

\subsection{Introduction: The Optimizer Input}
As with other entities, the Optimizer gets its own XML block in the RAVEN input.
Here's an example of an input for a SPSA optimizer named \xmlString{opter}:
\xmlExample{framework/user_guide/optimizing/simple.xml}{Optimizers}
This is the smallest amount of input needed to run an optimization problem, with the exception that we include
the \xmlNode{initialSeed} to maintain consistent results.  Note the required blocks included
to define the optimizer:
\begin{itemize}
  \item \xmlNode{objective}, which is where you indicate the variable for which you want to find the minimum (or,
    if you change the default, maximum).  As listed here, we want to minimize the value of \texttt{ans} given a
    range of possible values for \texttt{x} and \texttt{y}.
  \item \xmlNode{variable}, which is where you can define the input space variables, one for each of these
    nodes.  Declaring a variable here informs the optimizer that you want it to find the optimal value for
    this variable, along with the other variables declared in their own blocks. Note this follows
    the same pattern as any other \xmlNode{Sampler}, including a \xmlNode{distribution} node to
    describe the domain of the variable. For \xmlNode{GradientDescent}, the shape of the
    distribution is not significant unless performing other advanced optimizations (such as
    optimization at risk). Nominally, this distribution simply defines the acceptable range of the
    variable, making the \xmlNode{Uniform} distribution a common choice. The distribution sets the
    upper and lower bounds of the variable, which will give the optimizer some general expectations for
    finding the optimal point; it will never try to sample a value smaller than the lower bound or larger than
    the upper bound.  In the example we define variables \emph{x} and \emph{y} as our input variables, and
    both of them coincidentally range between -4.5 and 4.5.  We set the initial values for both variables to 0
    through the \xmlNode{initial} block, which is required in most cases; the exception is when a
    preconditioner sets them in mulitlevel optimization, but we're not concerned with that feature
    for this example.
  \item \xmlNode{TargetEvaluation}, which declares the DataObject that the optimization search evaluations are
    going to be placed in.  All of the optimal points found as part of the optimization, as well as any other
    points evaluated as part of the algorithm, are placed in this object so the optimizer can retrieve this
    information later.  When this data object is defined, it is critical that the objective variable is
    defined in the output space, and the input variables in the input space, so the optimizer can collect the
    results of its sampling.  The data object type should be ``PointSet'' for this data object.  In this
    example, we use the self-descriptive \emph{optOut} data object.
  \item \xmlNode{samplerInit}, which contains initialization parameters for the optimization
    algorithm. In this case, we set an \xmlNode{initialSeed} to 1234 just to maintain consistent
    results. We also set the maximum number of model evaluations through the \xmlNode{limit} node.
    We don't expect to need all these runs, but in case the optimizer is struggling, we set this
    cutoff to prevent the code running ad infinitum.
  \item \xmlNode{gradient}, which defines the gradient approximation algorithm to use within the
    gradient descent algorithm. In this case,
    we simply indicate that we want to use \xmlNode{SPSA}, and need no additional inputs.
  \item \xmlNode{stepSize}, which defines how we should control the step size during the gradient
    descent algorithm. There are several algorithms to choose from; in this case, we choose
    \xmlNode{GradientHistory}, which uses the scalar product between successive steps to determine
    what step to take in the search algorithm. A bigger growth factor results in traversing the input space more
    quickly, but converging more slowly. A bigger shrink factor results in collapsing to a minimum
    more quickly, converging quickly but possibly falling into local minima. We're using the default
    growth (1.25) and shrink (1.15) factors here.
  \item \xmlNode{acceptance}, which determines the algorithm by which we decide whether to accept a
    potential new optimal point during the gradient descent algorithm. In this case we use
    \xmlNode{Strict}, which indicates any potential new optimal points in the search that are not
    preferrable to the previously-found optimal point are discarded, and the search continues from
    the previously-found optimal point in the search.
  \item \xmlNode{convergence}, which informs the searching algorithm of when to decide it has found
    the optimal point within a sufficient tolerance. There are several stopping criteria; in this
    case, we use the local value of the \xmlNode{gradient}, which we want to be at most 0.1.
\end{itemize}
The other critical blocks in this input are as follows:

\subsubsection{Models}
\xmlExample{framework/user_guide/optimizing/simple.xml}{Models}
Note that we define the external model with the name \xmlString{beale} and provide a path to the analytic
model itself.  This model is set up with the \texttt{run} method that allows RAVEN to run the model.  We also
list all our input/output variables, \emph{x, y}, and \emph{ans}.

\subsubsection{Data Objects}
\xmlExample{framework/user_guide/optimizing/simple.xml}{DataObjects}
We have three data objects:
\begin{itemize}
\item \xmlString{placeholder}, which is necessary to define the input to our external
model in the Steps (the external model doesn't use any input file, so we just use a placeholder
here);
\item \xmlString{optOut}, which will hold all of the samples taken by our optimizer (optimal
candidates, gradient evaluation points, rejected points, etc); and
\item \xmlString{opt\_export}, which will hold the actual solution path taken by our optimizer.  We store the
path travelled by the optimization algorithm as successive samples, with \texttt{iteration} keeping track of the
optimization steps taken.  Note especially how the input of \xmlString{opt\_export} is set to \texttt{trajID},
which is a special keyword for the Optimizer trajectory tracking, as is the output variable \texttt{iteration}.
There are several other special keyword outputs that can be written to the Solution Export data object, that
can be found in the user manual.
\end{itemize}

\subsubsection{Out Streams}
\xmlExample{framework/user_guide/optimizing/simple.xml}{OutStreams}
Here we define the way to print the output of our optimization algorithm.  There's not much to note, except
that we'll be printing the optimization path as a CSV.

\subsubsection{Steps}
\xmlExample{framework/user_guide/optimizing/simple.xml}{Steps}
Here we put it all together into a work flow that RAVEN can follow.  We only need two steps: one to optimize,
and one to print out the results.  To actually perform the optimization, we need a MultiRun step, which we
cleverly name \xmlString{optimize}.  For input we take the placeholder data object \emph{placeholder}, which sets
up the input space of the model we defined, \emph{beal}.  Where a \xmlNode{Sampler} would normally go, we
include the \xmlNode{Optimizer} we defined earlier.  We output to the same data object we indicated in the
Optimizer's \xmlNode{TargetEvaluation} node.  Finally, we note specifically the use of the
\xmlNode{SolutionExport} node.  The data object defined in this node is where the Optimizer will write the
optimization path history, with the final entry being the last step taken by the optimizer.  The IOStep is
unremarkable, used simply to write out the optimization path history to file.

\subsubsection{Conclusion}
After reviewing the components (don't forget the RunInfo block!), you can run this example and see the
results.  In particular, we can view the final results of the optimizer in \texttt{Simple/opt\_export\_0.csv}.  Note
that \texttt{opt\_export} is the name of the \xmlNode{Print} OutStream we defined in the input file.

When we open the file (preferably in a CSV reader such a spreadsheet viewer), we see a CSV with several headers,
the outputs defined in the data object in the input
file: \emph{trajID}, \emph{iteration}, \emph{x}, \emph{y}, and \emph{ans} (not necessarily in that order).  \emph{x},
\emph{y}, and \emph{ans} are the values of the variable at each optimization iteration, while
\emph{iteration} gives the sequential order of the optimization iteration. \emph{trajID} is the
trajectory identifying number; since we are only using one trajectory, this identifier is simply 0.

We can see there's only one line of data in the ouput CSV, showing the final solution discovered by
the optimization algorithm.
If we look at the line, we converged around $f(2.7, 0.42) = 0.0199$ in 40 steps, which is okay but still a little
ways from the analytic optimal point $f(3, 0.5) = 0$.  If we look at the output from the run, we can look at
the last time RAVEN was ``Checking convergence for Trajectory 0''.  Below that statement, there are a series
of convergence criteria and their respeective statuses.  We can see our convergence criteria
requested through the input file (\texttt{gradient}, whose final accepted value is 0.0857) as well
as the \texttt{same point} convergence criteria, which helps determine if the optimal solution is at
a boundary even though other conditions have not converged.

We can see that the reason we converged at the end is the
\texttt{gradient}, which means the relative change in the gradient of \emph{ans} was sufficiently
small between steps to cause convergence.  Clearly, we claimed convergence prematurely because of
the low value required in the optimizer input.  Because these convergence criteria are very
problem-specific, one set parameters will not work best for all problems.

We can improve this result by changing convergence
parameters as well as step size growth and shrink factors, all of which can be found in the user manual, and
many of which we'll discuss in the rest of this section. Feel free to experiment with these values,
and see their affect on the solution discovered.

\subsection{Increasing verbosity}
We saw in the previous section that the output stored in \texttt{Simple/opt\_export.csv} only
includes the final optimal solution, and minimal information about that point. We can increase the
output to see the entire path traversed by adding a few parameters in the input file.

The first parameter to add is in \xmlNode{Optimizers} \xmlNode{GradientDescent}
\xmlNode{samplerInit}. By adding the node \xmlNode{writeSteps} with the value \xmlString{every}, we
can see the full path taken by the optimizer from initial point to final accepted solution.

Further, the optimizer has some special variables that can be use in the \xmlNode{SolutionExport}
\xmlNode{DataObject} to print additional information to the CSV. For example, the special variable
\texttt{accepted} will tell us, for each point in the optimization path, what the result of that
point is. For SPSA, these acceptance notes can be one of the following:
\begin{itemize}
  \item \texttt{first}, or the initial point at which the optimization search begins;
  \item \texttt{accepted}, if the new proposed point is sufficiently improved to be accepted as a
    new optimal point in the search;
  \item \texttt{rejected}, if the new proposed point is \emph{not} sufficiently improved and
    therefore rejected;
  \item \texttt{rerun}, indicating the search algorithm returned to an old optimal point after
    rejecting a proposed optimal point; and
  \item \texttt{final}, which shows that the point listed is the final accepted and converged
    optimal point.
\end{itemize}

\subsection{Initial Conditions and Parallel Trajectories} \label{subsec:opt parallel traj}
Notice we set the optimization search to start at $(0,0)$.
You can change this initial value through
the \xmlNode{initial} block within the \xmlNode{variable} definition nodes.

Furthermore, RAVEN offers the possibility to run multiple optimization paths in parallel.  Because many
(perhaps most) optimization techniques get stuck in local minima, using multiple paths (or \emph{trajectories} as
they are called in RAVEN) increases the likelihood that one of the trajectories will find the global minimum
point.  You can request multiple trajectories by providing a variety of initial conditions in the
\xmlNode{initial} block, as shown in this Optimizer example:
\xmlExample{framework/user_guide/optimizing/multiple_trajectories.xml}{Optimizers}
Note that the ordered pairs are split across the \xmlNode{initial} nodes, so that the first trajectory will
start as a point made up of all the first entries, the second trajectory starts at all the second entries, and
et cetera.  In this case, we've requested starting points at (-2,-2), (-2,2), (2,-2), and (2,2).  This (and
defining a new working directory in the \xmlNode{RunInfo} block) is the only input change between the original
file and this one.

When run, we can see the results in the working directory \texttt{MultipleTraj}.  There, we see the same files
as for the base case, plus \texttt{opt\_export} files 0-3.  These are produced because we've
clustered the outputs by \texttt{trajID} in the \xmlNode{OutStreams} definition. Each of these corresponds to the
path that one of the initial points started at, as you can see at the top of each of these CSV files.  We can
see that trajectory 2 (who started at (2,-2)) ended close to the analytic optimal point, while trajectory 1
was far from it.

In the screen output from the RAVEN run, you can see the final summary shows the status of each
trajectory. Under \emph{Trajectory Results} we see trajectories 1-3 all converged with different
optimal values, while trajectory 0 is marked as \emph{following 1}. This means at some point
Trajectory 0 started following the same path as Trajectory 1 already moved along, so Trajectory 0
was terminated as a result to save computational resources.

Finally, we see the optimal point selected was Trajectory 2 with a function value of roughly 3.7e-3
at (3.15, 0.54).

\subsection{Adjusting Adaptive Steps} \label{subsec:opt stepsize}
As we've seen, some of the optimization paths are struggling to converge to meaningful optimal solutions.
One way to improve this is to tinker with the convergence tolerances as shown in the user manual.  Another is
to change the step size modifications used as part of the search process, which we discuss in this section.
First, we briefly discuss how the SPSA chooses its step size, so we can make informed choices about what
parameters to use.

Because SPSA is a gradient-based method, it operates by starting at a particular point, estimating the
gradient at that point, then taking a step in the opposite direction of the gradient in order to follow a
downhill path.  It adaptively chooses how long of a step to take based on its history.  If the gradient is in
the same direction twice in a row, the algorithm assumes there's further to travel, so increases its step size
multiplicatively by the \emph{growthFactor}, which we had defaulted to 1.25.  If, on the other hand,
the gradient switches directions, then the step size is divided by the \emph{shrinkFactor}, which we
had defaulted to 1.15.  This means that by default, if the gradient keeps going in the same direction, you
always increase your step size by 25\%, while if you're bouncing back and forth in a valley, the
step size is reduced by 15\% at each iteration.

By way of note, in higher dimensions, the actual growth or shrink multiplier is scaled by a dot product
between the two previous gradients, with a max of the grain growth factor when the dot product is 1 (exactly
aligned) and a minimum of grain shrink factor when the dot product is -1 (exactly opposite).  This means if
the gradient is at right angles with the past gradient, then the step size remains unchanged (dot product is
0).

There are some additional considerations for the step size change, as well.  If the algorithm takes a step,
then discovers the new point has a worse response value than the point it's at, it will reject the new point,
re-evaluate the gradient, and flag the step size to be divided by the gain shrink factor.  Because of this, if
the gain shrink factor is too large, false convergence can be obtained when the algorithm struggles to find a
new downhill point to move to.  As a result, in practice it is often beneficial to have a gain shrink factor
that is smaller than the gain growth factor.

For this new example, we use gain growth factor of 1.25 (meaning when the gradient continues in the same
direction our step grows by 25\% of its old value) and a gain shrink factor of 1.1 (meaning when the
gradient flips directions our step size shrinks to 90\% of its old value).  We add this to the base case
(\texttt{simple.xml}) to get:
\xmlExample{framework/user_guide/optimizing/step_size.xml}{Optimizers}
Note the definition of the gain growth and shrink factors in the \xmlNode{convergence} block.  Reviewing the
output file \texttt{StepSize}, we can see more steps were taken than the case using default step sizes, but
the final solution was $f(2.75,0.430)=0.013$ in 40 iterations, which is closer to the analytical solution of $f(3,0.5)=0$
than the original case using the same number of iterations.

It is often challenging to find the best gain growth and shrink factors, and these can have a very significant
impact on the speed and accuracy of the convergence process.  Too large a shrink factor results in poor
resolution of valleys, while too small a shrink factor results in many unnecessary evaluations of the model.

% TODO rewrite with new sampler-based denoising options
% \subsection{Denoising Stochastic Problems}
% While many of the models we see in optimization are deterministic (meaning running the same inputs into the
% model yields the same results every time), there are quite a few stochastic models that we might desire to
% optimize.  For example, a model that included Brownian motion or is solved using unseeded random numbers might
% be considered stochastic.

% The difficulty with optimizing noisy problems rests in the unreliability of a single sample.  If we send a
% single set of inputs into a stochastic model, we can't trust the results to be consistent.  One way to measure
% the consistency of the results is through a signal-to-noise ratio (SNR).  There are many ways to define this
% value; for our purposes, we will use the ratio of the mean of the signal to the standard deviation of the
% signal, $\mu/\sigma$.

% To obtain an approximation of your SNR, you can use RAVEN to perform a Monte Carlo run on your model and then
% use the BasicStatistics postprocessor to collect the mean (expectedValue) and standard deviation (sigma) of
% your response.  It's important to make this sampling all at a single value in the input space, so replace your
% variables with constants in the Sampler input.  Once you have the mean and sigma, you have an idea of how
% noisy your model is.  A SNR of 1 means the signal is just as big as the noise, making it very difficult to
% optimize.  A SNR of less than 1 means the noise dominates the signal, and will make optimization almost
% impossible without introducing denoising.  A SNR of more than 1 indicates the signal is stronger than the
% noise, and perhaps denoising is not necessary.  If your standard deviation is 0, then you don't have any
% discernable noise!

% To denoise a model in RAVEN SPSA optimization currently, we turn our attention to the \xmlNode{Optimizer}
% subnode \xmlNode{parameter}, specifically the \xmlNode{numGradAvgIterations} node.  This parameter instructs
% RAVEN to perform multiple gradient evaluations, including multiple evaluations of each optimal point, and use
% the average to make decisions in optimization pathing.  By default, RAVEN takes one optimal point and one
% neighboring point to evaluate a gradient.  Increasing the \xmlNode{numGradAvgIterations} will increase the
% number of times the optimal point is sampled, and how many neighbor points are sampled.  This serves to
% denoise the model.

% However, this also raises the question, how many resamples do I need to denoise my model?  In a Wilks-like
% approach, we want to reduce the size of the confidence interval for our mean to be less than the noise.  The
% number of resamples required depends on the size of the confidence interval $z$ and the confidence-to-noise ratio
% $\xi$ we want to ultimately have for the optimization algorithm.  We also assume the distribution of the
% response is roughly Gaussian Normal, which may not be the case.  The approximate equation for assuring the
% confidence interval is smaller than the noise is
% \begin{equation}
%   \frac{z\sigma}{\sqrt{n}} \leq \xi\sigma,
% \end{equation}
% \begin{equation}
%   n \geq \left(\frac{z}{\xi}\right)^2.
% \end{equation}
% Thus, the number of resamples depends on the confidence level as well as the desired ratio of the confidence interval
% to the noise.

% A few values for varying ratios are given in Table \ref{tab:confidence levels} for the 99\% confidence level ($z=2.576$).
% \begin{table}[htb]
%   \centering
%   \begin{tabular}{c c}
%     Confidence-to-noise $\xi$ & Resamples necessary \\ \hline
%     1.0 & 7 \\
%     0.9 & 9 \\
%     0.7 & 14 \\
%     0.5 & 27 \\
%     0.1 & 664 \\
%     0.05 & 2655
%   \end{tabular}
%   \caption{Estimate of the number of samples necessary to denoise models to varying confidence levels}
%   \label{tab:confidence levels}
% \end{table}
% That is, if you want the noise and confidence interval to have the same magnitude, only 7 resamples are
% required.  If, on the other hand, you want the confidence interval to be half the level of the noise, 27
% resamples are required.

% Note these are only guidelines; individual models may behave differently and require more or less resamples to
% provide a clear optimization path.

\subsection{Functional Constraints} \label{subsec:opt explicit constraint}
Sometimes an optimization problem has a constrained input space, possibly where there is a tradeoff between
two inputs.  In this event, RAVEN allows the user to define a \emph{constraint} function, which will cause
RAVEN to treat this constraint as it would a boundary condition.

For example, we will introduce a void in the input where we reject inputs.  This void is defined by rejecting
all samples within $(x-1)^2 + y^2 < 1$.  We'll also include the modified step growth and shrink parameters
discussed in section \ref{subsec:opt stepsize}.

To include a constraint function, we first have to define it in the RAVEN input as a \xmlNode{Function}
entity:
\xmlExample{framework/user_guide/optimizing/constrain.xml}{Functions}
Note that the file \texttt{./Constrain/constraint.py} is located relative to the working directory.  Currently,
external functions are always Python files.  In that file,
note that the only method is \texttt{constrain}, which is RAVEN's keyword to find the constraint function.
RAVEN will pass in a \texttt{self} object, which will have the function variables defined in the
\xmlNode{Functions} input available as members.  The method \texttt{constrain} then returns a boolean which is \texttt{True} if
the evaluation does not violate the constraint, or \texttt{False} if the constraint is violated.

To attach the constraint to the optimizer, simply add it as an assembled \xmlNode{Function}:
\xmlExample{framework/user_guide/optimizing/constrain.xml}{Optimizers}

After running, looking through the path followed by trajectory 0 shows that instead of following the path from
section \ref{subsec:opt stepsize}, the path moves to lower \emph{y} values before swinging back up toward the
optimal point.

%\subsection{Implicit Constraints (Penalties)}
% TODO come up with a working example


\section{Formatting}

A thesis is written with a single-column layout on one- or two-sided
A4 sheets. The font type of the body text is usually Times New Roman
and the font size is 12 pt. The text is fully justified and hyphenated.
You do not have to indent the paragraphs.

\subsection{Mathematical notations}

Numbers are generally written using numerals for the sake of clarity,
for example ``6 stages'' rather than ``six stages''. You should
also use a thousand separators\footnote{Use tilde \~{} in LaTeX and a
  special character \textit{non-breaking space} in MS Word},
i.e. instead of 55700125 write 55~700~125. Never omit the leading zero
in decimals. For example, it is correct to write ``0.5'' and wrong to
write ``.5''. A comma is used as a decimal separator in the Estonian
language and a period in the English language.

Like numbers, it is advisable to abbreviate units of
measurement. There is a space between the number and the unit, but you
should keep them on the same line. It is better to compile a table or
graph than include a great deal of numerical values in the body
text. Use precise language and put numbers on a scale.

Newton's Second Law can be presented in the following way:

\begin{equation}
  \label{eq:newton2}
 F = ma,
\end{equation}

where $m$ denotes the mass of an object, $a$ means acceleration, and
$F$ means force. Please note that all the variables must be defined at
the point of their first appearance. All sentences end with a
punctuation mark, and the main elements of a sentence are separated by
a comma in accordance with the rules of English grammar. Consider formulas
as part of a sentence, therefore use commas or period accordingly after
formulas (e.g. see equation (\ref{eq:newton2})).

Formulas can be numbered or not numbered. Numbered formulas are used if there is need to refer to these formulas later on. For example, let us have a formula
\begin{equation}\label{eq:pythagoras}
c^2=a^2+b^2.
\end{equation}
Then, since \eqref{eq:pythagoras} is numbered, we can always refer to it in later text. For example, specifying $a=3$ and $b=4$ and applying \eqref{eq:pythagoras} implies $c=5$.

On the other hand, if we do not refer to some formula or equation at all, it should not have a number, for example:
\[
S_n=\sum_{i=1}^n X_n.
\]

Occasionally mathematical notations are preceded by an
identifier, such as 'Definition 1' or 'Theorem 1'. Simple formulas may
be displayed within the body of the text without numbering.

Please note that usually different styles applied to same letter/symbol refer to different object, for example, $x$, x, $X$, \textit{\textbf{X}}, $\mathbf{X}$, ..., are all different. Also, a general rule is that variables are in italic and function names are in regular font, for example, $s$, $u$ and $p$ are some variables, and supremum function $\sup$ is in regular font so we do not confuse it with the product $sup=s\cdot u\cdot p$.

Please try to use unified notation (i.e. same letter/symbol should mean the same variable or function) throughout the whole document (as much as possible).

LaTeX is the best editor for writing also the more complex equations, such as
\begin{equation}
  \label{eq:fourier}
  G^+(t,t')= \int G^+(E) \exp[-iE(t-t')/\hbar] dE.
\end{equation}

\subsection{Theorems and definitions}

Mathematical thesis often include elements that require special formatting and numbering such as theorems, definitions, propositions, remarks, corollaries, lemmas and so on. Such formatting can be achieved by defining special environment with the \verb+\newtheorem+ command in the preamble of the document. For example:

\begin{theorem}
Let $f$ be a function whose derivative exists in every point, then $f$ is
a continuous function.
\end{theorem}

\begin{proof}
If a derivative of function $f$ exists in point $x_0$ (meaning that $f$ is differentiable at point $x_0$), then $f$ is continuous at point $x_0$ (differentiability implies continuity - not proven here).

Assume that function $f$ is differentiable in every point, then that implies that $f$ is continuous at every point and $f$ is a continuous function.
\end{proof}

For the next theorem we need a definition:

\begin{definition}
A right triangle is a triangle in which one angle is a right angle (that is, a 90-degree angle).
\end{definition}

Notice that the definition does not have a number. This can be achieved by defining the definition environment with the \verb+\newtheorem*{}+ command.

\begin{theorem}[Pythagorean theorem]
\label{pythagorean}
This is a theorem about right triangles and can be summarised in the next
equation
\[ x^2 + y^2 = z^2 \]
\end{theorem}

And a consequence of Theorem \ref{pythagorean} is the statement in the next
corollary (you can reference theorems when a label is assigned).

\begin{corollary}
There's no right rectangle whose sides measure 3cm, 4cm, and 6cm.
\end{corollary}

Notice that the Corollary has different numbering, this is because the environment is defined with \verb+\newtheorem{corollary}{Corollary}[theorem]+ , where the square brackets determines the environment that will be used for numbering (also refered to as counter). The same logic can be applied to formulas and theorems, if there are many of such elements. Often the counters are determined by section, for example "Theorem 2.3" refers to the 3rd theorem in the 2nd section of a document.

By default, each theorem uses its own counter. However it is common for similar types of theorems (e.g. Theorems, Lemmas and Corollaries) to share a counter. In this case, define subsequent theorems as:
\begin{verbatim}
\newtheorem{<name>}[<counter>]{<Printed output>}
\end{verbatim}
where counter is the name of the counter to be used.

\subsection{Figures}

You must refer to all the figures in the body text. The reference
should preferably appear on the same page as the actual figure or
before it (e.g. Figure~\ref{fig:ex_fig}). Figures and tables must be numbered consistently thesis
and primarily placed at the top of the page, but you are free to
decide where they fit best. Never start a chapter with a figure, table
or list.
% Note: put tilde between text and ref command, like in
% 'Figure~\ref{fig:ex_fig}' above. Tilde (~) puts a white space but
% prevents line break. Same thing applies to Table~\ref{tab:summary}
% as well.

Figures and the caption are consistently centered  and the caption is
placed under the figure and always on the same page as the figure.
All figures must be explained in the body text, so that readers know
what they are supposed to notice.

The figures should be in the same language as other text. The recommended
font size is the same as that of the body text but no smaller than 10 pt.
The figures must be readable, even if your thesis is printed in grey-scale!

% Here's an example how to add a figure. Default placement of figures
% is at top of page, i.e. placement specifier is '[t]' could be
% omitted.  The dimensions can be relative to text width (or height)
% or absolute (4 cm).

\begin{figure}[t]
  \begin{center}
    \includegraphics[width=0.7\textwidth]{figure}
  \end{center}
  \caption{Diagram of achieved height and time of flight with different angles of release.}
  \label{fig:ex_fig}
\end{figure}

\subsection{Tables}

Tables have numbered captions, see Table\ref{tab:thin_film} for
example. The caption is placed on the same page above the table. You
must refer to all the tables in the body text. In addition, you must
discuss the content of any tables in the body text to ensure that readers
understand their relevance.

\begin{table}[ht]
  \small
  \begin{center}
    \caption{Example of evaporation conditions in a thin film structure.}
    \label{tab:thin_film}
    \begin{tabular}{l | r r r r r}
      % l = align to left (e.g. text), c=align to center, r=align to
      % right (e.g. numbers), Pipe | creates vertical line
      % Let's put 1 horinzontal line above the table, 2 after header rows,  and 1 below
      \hline
      \textbf{Substance} & \textbf{Thickness}& \textbf{Correction } & \textbf{Pressure}  & \textbf{Current} & \textbf{Speed} \\
                         & \textbf{(nm)}     & \textbf{coefficient} & \textbf{(mbar)}    & \textbf{(mA)}    & \textbf{(nm/s)} \\
      \hline
      SiO$_2$	& 181.0	& 1.10	& $3.0\cdot10^5$	& 20-23	 &0.2 \\
      TiO$_2$	& 122.1	& 1.55	& $1.5\cdot10^4$	& 100-93 &0.1 \\
      \hline
    \end{tabular}
  \end{center}
\end{table}

Often it is better to create the table in, e.g. MS Excel, and import
it as .eps or .pdf file, for example, when you calculate some of the
values automatically.
%\begin{table}[h]
%  \begin{center}
%    \caption{Example of evaporation conditions in a thin film structure.}
%    \label{tab:thin_film_graphics}
%    \includegraphics[width=8cm]{my_table.eps}
%  \end{center}
%\end{table}

You can use boldface to highlight the header row. Do not surround all
the cells with a border, as it may make your table harder to read.
Put a line on top and bottom of the table. You can add a horizontal line
grouped into categories.

The numbers are right aligned (optimally lined up at the decimal
point) for easy comparison. You should preferably use SI units,
established prefixes and rewrite large numbers so that the power of
ten should be placed in the title of the column instead of each row,
if possible.

\subsection{Programs and algorithms}

Codes and algorithms are written using mono-spaced font, such as
Courier New, Consolas or their variations. If the length of the code
or algorithm is less than 10 lines and you do not refer to it later on
in the text, you can present it similarly to formulas.  Here's an
example showing a snippet (install package \verb!listings! for coloring your code according to type):

\begin{verbatim}
\begin{lstlisting}[style=console, % title={Template files} ]
all: ${TARGET}.tex
	pdflatex ${TARGET}.tex
	bibtex ${TARGET}
	pdflatex ${TARGET}.tex
\end{lstlisting}
\end{verbatim}

If the code is longer but shorter than a page, you present like a
figure (Program 4.1) titled ``Program'' or ``Algorithm''.
You should add some comments to the code and indent it
consistently. The actions performed by the code must be outlined in
broad terms in the body text. Line numbers make it much easier to
refer to the code in the text.

LaTeX has a packages that enable automatic code formatting like
highlight reserved words, bring out string input or color comments differently.


\subsection{Circular disk with an edge crack in tension}

\paragraph{}
Next, the present formulation is applied to problems with strong discontinuities and singularities.
The unique feature of the proposed framework is that the geometry is exactly represented by using NURBS and the singularities are captured semi-analytically without a priori knowledge of the asymptotic fields.
In the first example, consider a circular disk with an edge crack (see Fig.~\ref{iso_fig:circular_disk_geo_bc}) with Young’s modulus $E=\SI{1}{\newton \per \square \meter}$ and Poisson's ratio $\nu=0.3$.
    \begin{figure}[h!]
        \centering
        \scalebox{0.4}{
            \includegraphics{isogeometric_sbfem/images/circular_disk_geo_bc.eps}
        }
        \caption{Circular disk with an edge crack}
        \label{iso_fig:circular_disk_geo_bc}
    \end{figure}

The analytical displacements solution for mode \RN{1} are given by:
    \begin{subequations}
        \begin{align}
            u_x &= \frac{1}{2}\left[
                \left(
                    \kappa + \frac{n}{2} + (-1)^n
                \right) \cos \left(
                    \frac{n\theta}{2}
                \right) -
                \frac{n}{2} \cos \left(
                    \left(
                        \frac{n}{2} -2
                    \right) \theta
                \right)
            \right]\\
            u_y &= \frac{1}{2}\left[
                \left(
                    \kappa - \frac{n}{2} - (-1)^n
                \right) \sin \left(
                    \frac{n\theta}{2}
                \right) +
                \frac{n}{2} \sin \left(
                    \left(
                        \frac{n}{2} -2
                    \right) \theta
                \right)
            \right]\\
        \end{align}
    \end{subequations}

where $\kappa$ is the Kolosov constant defined in Eq.~\ref{iso_eq:kolosov_constant}.

The analytical stress solution for mode \RN{1} are given by:
    \begin{subequations}
        \begin{align}
            \sigma_{xx} &= \frac{n}{2}\left[
                \left(
                    2 + \frac{n}{2} + (-1)^n
                \right) \cos \left(
                    \left(
                        \frac{n}{2} - 1
                    \right)\theta
                \right) - \left(
                    \frac{n}{2} - 1
                \right)
                \cos \left(
                    \left(
                        \frac{n}{2} -3
                    \right) \theta
                \right)
            \right]\\
            \sigma_{yy} &= \frac{n}{2}\left[
                \left(
                    2 - \frac{n}{2} - (-1)^n
                \right) \cos \left(
                    \left(
                        \frac{n}{2} - 1
                    \right)\theta
                \right) + \left(
                    \frac{n}{2} - 1
                \right)
                \cos \left(
                    \left(
                        \frac{n}{2} -3
                    \right) \theta
                \right)
            \right]\\
            \tau_{xy} &= \frac{n}{2}\left[
                \left(
                    \frac{n}{2} - 1
                \right) \sin \left(
                    \left(
                        \frac{n}{2} - 3
                    \right)\theta
                \right) - \left(
                    \frac{n}{2} + (-1)^n
                \right)
                \sin \left(
                    \left(
                        \frac{n}{2} - 3
                    \right) \theta
                \right)
            \right]
        \end{align}
    \end{subequations}

\paragraph{}
In this example, the circular disk is represented by NURBS.
The control net and the location of control points are shown in Fig.~\ref{iso_fig:circular_disk_mesh} for different NURBS orders.
    \begin{figure}
        \begin{subfigure}[b]{0.5\linewidth}
            \centering
            \scalebox{0.4}{
                \includegraphics{isogeometric_sbfem/images/circular_disk_2nd_9cp.png}
            }
            \caption{9 control points, 2nd order}
        \end{subfigure}
        \begin{subfigure}[b]{0.5\linewidth}
            \centering
            \scalebox{0.4}{
                \includegraphics{isogeometric_sbfem/images/circular_disk_2nd_17cp.png}
            }
            \caption{9 control points, 2nd order}
        \end{subfigure}

        \begin{subfigure}[b]{0.5\linewidth}
            \centering
            \scalebox{0.4}{
                \includegraphics{isogeometric_sbfem/images/circular_disk_3rd_17cp.png}
            }
            \caption{9 control points, 2nd order}
        \end{subfigure}
        \begin{subfigure}[b]{0.5\linewidth}
            \centering
            \scalebox{0.4}{
                \includegraphics{isogeometric_sbfem/images/circular_disk_4th_17cp.png}
            }
            \caption{9 control points, 2nd order}
        \end{subfigure}
        \caption{Meshing of the circular disk with an edge notch}
        \label{iso_fig:circular_disk_mesh}
    \end{figure}

\paragraph{}
The circular disk is subjected to a far field tension and the displacement and the stress modes are computed by the proposed isogeometric SBFEM.
It is noted that only the boundary of the circular disk is discretized using the NURBS and no tensor product of the corresponding knot vectors is required to represent the unknown fields inside the domain.
The convergence of the numerical stress intensity factor (SIF) and the T-stress with mesh refinement is shown in Tab.~\ref{iso_tab:circular_disk_res}.

\begin{table}[]
\caption{T-stress and stress intensity factors for circular disk with an edge crack.}
\label{iso_tab:circular_disk_res}
\begin{tabularx}{\textwidth}{XXXXXXX}
\toprule
    Total    &   \multicolumn{2}{c}{NURBS $p=2$} &\multicolumn{2}{c}{NURBS $p=4$} &\multicolumn{2}{c}{NURBS $p=6$}\\
    \cmidrule{2-7}
    DOF      &   SIF     &   T-stress            &SIF     &   T-stress            &SIF     &   T-stress           \\
    \cmidrule{1-1} \cmidrule{2-3} \cmidrule{4-5} \cmidrule{6-7}
    18       &   2.3520  &   2.9442              &        &                       &        &                      \\
    34       &   2.8693  &   5.1991              &2.8838  &5.4050                 &        &                      \\
    74       &   2.8838  &   5.3112              &2.8840  &5.3445                 &2.8840  &5.3447                \\
    130      &   2.8840  &   5.3318              &2.8840  &5.3444                 &2.8840  &5.3444                \\
\bottomrule
\end{tabularx}
\end{table}

\paragraph{}
It can be seen that with mesh refinement the SIF and the T-stress converge.
Increasing the order of the NURBS functions increases the convergence behavior.
Eq.~\ref{iso_eq:isosbfem_fracture_stress_field} is the parametric equation for the stress field in the polar coordinates $r$ and $\theta$.
The terms $\left(
        r_\eta^{\lambda_i+1}(\eta)
        \boldsymbol{\psi}_{\sigma_i}(\eta)
    \right)$
in Eq.~\ref{iso_eq:isosbfem_fracture_stress_field} together with $\theta(\eta)$ in Eq.~\ref{lr_eq:sbfem_transform} are the stress modes describing the angular distribution at a constant radial coordinate $r$.
For the converged result, Fig.~\ref{iso_fig:circular_disk_modes} shows the displacement and the stress distribution at a constant radial coordinate r around the crack tip for mode \RN{1} fracture.
Each of the stress modes is normalized with its value of $\sigma_{yy}=0^\circ$ .
    \begin{figure}[h!]
        \begin{subfigure}[b]{1\linewidth}
            \centering
            \scalebox{0.4}{
                \includegraphics{isogeometric_sbfem/images/circular_disk_displacement_modes.png}
            }
            \caption{displacements}
        \end{subfigure}
        \begin{subfigure}[b]{1\linewidth}
            \centering
            \scalebox{0.4}{
                \includegraphics{isogeometric_sbfem/images/circular_disk_stress_modes.png}
            }
            \caption{stress}
        \end{subfigure}
    \caption{Displacement and stress modes of circular disk with an edge crack using cubic NURBS functions}
    \label{iso_fig:circular_disk_modes}
    \end{figure}

\paragraph{}
The stress modes from the scaled boundary formulation are compared with the analytical solutions and a very good agreement is observed in Tab.~\ref{iso_tab:circular_disk_res}.
The convergence of the displacement and stress modes with h and p refinement is shown in Fig.~\ref{iso_fig:circular_disk_convergence}.
It can be seen that with refinement the solution converges monotonically.
    \begin{figure}[h!]
        \begin{subfigure}[b]{1\linewidth}
            \centering
            \scalebox{0.65}{
                \includegraphics{isogeometric_sbfem/images/circular_disk_convergence_displacement.eps}
            }
            \caption{Displacement mode}
        \end{subfigure}

        \begin{subfigure}[b]{1\linewidth}
            \centering
            \scalebox{0.65}{
                \includegraphics{isogeometric_sbfem/images/circular_disk_convergence_displacement.eps}
            }
            \caption{Displacement mode}
        \end{subfigure}
    \caption{Circular disk with an edge crack: convergence of the displacement mode and stress mode}
    \label{iso_fig:circular_disk_convergence}
    \end{figure}


\documentclass[11pt]{article}

%% WRY has commented out some unused packages %%
%% If needed, activate these by uncommenting
\usepackage{geometry}                % See geometry.pdf to learn the layout options. There are lots.
%\geometry{letterpaper}                   % ... or a4paper or a5paper or ...
\geometry{a4paper,left=2.5cm,right=2.5cm,top=2.5cm,bottom=2.5cm}
%\geometry{landscape}                % Activate for rotated page geometry
%\usepackage[parfill]{parskip}    % Activate to begin paragraphs with an empty line rather than an indent

%for figures
%\usepackage{graphicx}

\usepackage{color}
\definecolor{mygreen}{RGB}{28,172,0} % color values Red, Green, Blue
\definecolor{mylilas}{RGB}{170,55,241}
%% for graphics this one is also OK:
\usepackage{epsfig}

%% AMS mathsymbols are enabled with
\usepackage{amssymb,amsmath}

%% more options in enumerate
\usepackage{enumerate}
\usepackage{enumitem}

%% insert code
\usepackage{listings}

\usepackage[utf8]{inputenc}

\usepackage{hyperref}

%% colors
\usepackage{graphicx,xcolor,lipsum}

\usepackage{mathtools}

\usepackage{graphicx}
\newcommand*{\matminus}{%
  \leavevmode
  \hphantom{0}%
  \llap{%
    \settowidth{\dimen0 }{$0$}%
    \resizebox{1.1\dimen0 }{\height}{$-$}%
  }%
}

\title{WKB approximate solutions for standard baroclinic modes}
\author{Cesar B Rocha\thanks{Scripps Institution of Oceanography, University of California, San Diego; \texttt{crocha@ucsd.edu}}}
\date{\today}

\begin{document}

\include{mysymbols}

\maketitle

In these notes I derive approximate WKB solutions to the standard baroclinic modes of physical oceanography. The elementary textbook example with constant buoyancy frequency is recovered as a special case.

\section{Pressure modes}

The standard baroclinic modes for pressure, here denoted $\sp_n(z)$,  is defined by the regular Sturm-Liouville eigenproblem

\beq
\label{eigpb}
\sL \sp_n = -\kappa_n^2 \sp_n\com
\eeq
with homogeneous Neumann boundary conditions
\beq
\label{bc}
@z = -h,\,0:\qquad \sp_n' = 0\com
\eeq
and the self-adjoint Linear operator
\beq
\label{strech}
\sL \defn \frac{\dd}{\dd z}\frac{f_0^2}{N^2}\frac{\dd}{\dd z} \per
\eeq
Hence the eigenmodes, $\sp_n$, are orthogonal. The eigennvalue $\kappa_n$ is the deformation wavenumber of the $n$'th mode. It is convenient to normalize the eigenmodes to have unit $L^2$-norm:
\beq
\label{normalization0}
\frac{1}{H}\int_{-h}^{0}\!\! \sp_n \sp_m \dd z = \delta_{mn}\com
\eeq
where $\delta_{mn}$ is the Kronecker delta. Equation \eqref{eigpb} can be rewritten as
\beq
\label{eigpb_wkb}
\bur \sp_n'' + \left[\bur\right]' \sp_n' + \kappa_n^2 \,\sp_n = 0\per
\eeq
Introducing the following definitions
\beq
\label{notation}
\ep \defn \frac{1}{\kappa_n} \qquad \text{and} \qquad S^2(z) \defn \ibur \per
\eeq
we have the renotated equation
\beq
\label{dirich_eigpb_wkb_ep}
\ep^2\, \sp_n'' -\ep^2 \left[\log S^2(z)\right]' \sp_n' + S^2(z) \sp_n = 0\per
\eeq
In the WKB spirit we assume that $S^2(z)$ is slowly varying i.e., the buoyancy frequency $N^2(z)$ does not vary very fast. (This assumption may be problematic near the base of the mixed-layer.) We also assume that $\ep$ is small; the accuracy of the WKB solution improves with mode number. We now make the exponential approximation (e.g., Bender and Orszag)
\beq
\sp_n^e \defn \ee^{Q(z)/\ep}\per
\eeq
Hence
\beq
{\sp_n^e}' = \frac{Q'(z)}{\ep}\sp_n^e\com
\eeq
and
\beq
{\sp_n^e}'' = \left[\left(\frac{Q'(z)}{\ep}\right)^2 + \frac{Q''(z)}{\ep} \right]\sp_n^e\com
\eeq
Next we expand $Q(z)$ in powers of $\ep$
\beq
\label{aseries}
Q(z) = Q_0(z)  + \ep\,Q_1(z) + \ep^2\,Q_2(z) + \mathcal{O}(\ep^3)\per
\eeq
Substituting \eqref{aseries} in \eqref{dirich_eigpb_wkb_ep} we obtain, to lowest order, $\mathcal{O}(\ep^0)$,
\beq
\label{lowest_order_eqn}
Q_0'^2 + S^2(z) = 0\per
\eeq
Thus
\beq
\label{Q0}
Q_0 = \pm \ii \int^z \!\!\!S(\xi) \,\dd \xi  = \pm \ii \tfrac{1}{f_0} \int^z \!\!\!N(\xi) \,\dd \xi \per
\eeq
At next order, $\mathcal{O}(\ep)$, we have
\beq
\label{first_order_eqn}
2\,Q_0'Q_1' + Q_0'' - Q_0'  \left[\log S^2(z)\right]' = 0\per
\eeq
Hence
\beq
\label{Q_1}
Q_1  =   \frac{1}{2} \log S(z) - \frac{1}{2}\log \pm \ii S(z) + \text{const}\,\, \per
\eeq
Notice that the imaginary part in the $\log$ in \eqref{Q_1} just contributes an irrelevant constant. Thus
\beq
Q_1 = \log \sqrt{S(z)} + \text{const} \,\, \per
\eeq
In the most common WKB approximation (a.k.a ``physical optics'') we truncate \eqref{aseries} at $\mathcal{O}(\ep)$. The solution to \eqref{dirich_eigpb_wkb_ep}, consistent with the bottom boundary condition \eqref{bc}, is
\beq
\sp_n^{po} = A_n\, \sqrt{N(z)}\, \cos \left(\frac{\kappa_n}{f_0} \int_{-h}^{z} \!\!\!N(\xi) \dd \xi\right)\com
\eeq
where $A_n$ is a constant. By imposing the boundary condition at $z=0$ \eqref{bc}, we obtain the eigenvalues $\kappa_n$:
\beq
\label{kappan}
\kappa_n = \frac{n \pi \, f_0}{\overline{N}\,h} \com\qquad n=0,1,2,\ldots \com
\eeq
where the mean buoyancy frequency is
\beq
\label{N_avg}
\overline{N} \defn\frac{1}{h} \int_{-h}^0N(\xi)\dd \xi\per
\eeq
The constant $A_n$ is determined by the normalization condition \eqref{normalization0}. We have
\beq
\label{an_eqn}
A_n^2 \, \int_{-h}^{0}\!\! N(z) \cos^2 \left(\frac{\kappa_n}{f_0}\int_{-h}^{z}\!\!\!N(\xi) \dd \xi\right) \dd z = H\com\qquad n\ge 1\per
\eeq
The integral in \eqref{an_eqn} can be evaluated exactly by making the change of variables
\beq
\eta \defn \frac{\kappa_n}{f_0}\int_{-h}^{z}\!\!\! N(\xi) \dd \xi  \qquad \Rightarrow \qquad \dd\eta = \frac{\kappa_n}{f_0}N(z) \dd z\com
\eeq
and using the expression for the eigenvalues \eqref{kappan}. We obtain
\beq
A_n = \Big(2/\overline{N} \Big)^{1/2} \com\qquad n\ge 1\per
\eeq
Thus the WKB approximate solution to the standard pressure modes is
\beq
\sp_n^{po} = \left[\frac{2\,N(z)}{\Nb} \right]^{1/2}\!\!\cos\left( \frac{n \pi}{\Nb\,h} \,\,\,\int_{-h}^{z} \!N(\xi) \dd \xi\right)\com\qquad n\ge1\per
\eeq
The amplitude of the baroclinic modes  at the boundaries is independent of the eigenvalue:
\beq
\sp_n^{po}(z=0) = (-1)^{n} \left[\frac{2 N(0)}{\Nb}\right]^{1/2}\com
\eeq
and
\beq
\sp_n^{po}(z=-h) = \left[\frac{2 N(-h)}{\Nb}\right]^{1/2}\per
\eeq

The barotropic mode is not recovered from the WKB solution because $\kappa_0 = 0$. From \eqref{eigpb} we have that with $\kappa_0 = 0$, the barotropic mode is constant, independent of the stratification. With the normalization \eqref{normalization0} we obtain $\sp_0 = 1$.

\subsection*{Constant buoyancy frequency}
With $N = \text{const.}$  the modes are simple sinusoids. That exact result is recovered as a special case of the WKB solution
\beq
\sp_n^{po} = \sqrt{2} \cos\left[n \pi (1+z/h)\right]\per
\eeq

\section{Density modes}
Similarly the baroclinic modes for density, here denoted by $\sr_n$, are defined via the eigenproblem
\beq
\label{eig_prob_rho}
\sr_n'' = -\kappa_n^2 \ibur \sr_n\com
\eeq
with homogeneous Dirichlet boundary conditions
\beq
\label{rho_bc}
@z = -h,0: \qquad \sr_n = 0\com
\eeq
and normalization
\beq
\label{normalization2}
\frac{1}{h}\int_{-h}^0 \!\!\sr_n \sr_m \dd z = \delta_{mn}\per
\eeq
Alternatively, we can work on  the approximation from the beginning. The WKB approximate solution to \eqref{eig_prob_rho}-\eqref{rho_bc}, consistent with the bottom boundary conditions \eqref{rho_bc}, is
\beq
\sr_n^{po} = \frac{B_n}{\sqrt{N(z)}} \sin \left(\frac{\kappa_n}{f_0} \int_{-h}^{z} N(\xi)\dd \xi \right) \com
\eeq
The eigenvalues $\kappa_n$ are the same as before \eqref{kappan}. (This should be no surprise because it follows  from the definition of $\sp_n$ and $\sr_n$. Nonetheless,  the verification is a good sanity check.) To find $B_n$ we use the normalization \eqref{normalization2}
\beq
\label{bn_eqn}
B_n^2 \, \int_{-h}^{0}\!\!\frac{1}{N(z)} \sin \left(\frac{\kappa_n}{f_0}\int_{-h}^{z}\!\!\!N(\xi) \dd \xi\right) \dd z = h\com\qquad n\ge 1\per
\eeq
We use a similar trick as above i.e., we change variables with
\beq
\eta \defn \frac{\kappa_n}{N^2(z) f_0}\int_{-h}^{z}\!\!\! N(\xi) \dd \xi  \qquad \Rightarrow \qquad \dd\eta = \frac{\kappa_n}{N(z) f_0} \dd z\com
\eeq
where, in the WKB spirit, we used the fact that $N(z)$ is slowly varying when differentiating the relation above. We obtain
\beq
B_n = \Big(2 N^2(0)/\Nb\Big)^{1/2}\per
\eeq
Thus the WKB approximate solution to the density modes is
\beq
\label{rpo_final}
\sr_n^{po} = \left(\frac{2 N^2(0)}{\Nb N(z)}\right)^{1/2} \sin \left(\frac{n \pi}{\Nb\,h} \int_{-h}^{z} N(\xi)\dd \xi \right)\com\qquad n\ge 1 \per
\eeq
Finally, note that the modes are simply related
\beq
\frac{\dd \sr_n^{po}}{\dd z} = N(0) \underbrace{\frac{n\pi}{\Nb\,h}}_{=\kappa_n/f_0}\,\sp_n^{po}\per
\eeq

\subsection*{Constant buoyancy frequency}
Again we recover the $N = \text{const.}$ special case from \eqref{rpo_final}:
\beq
\sr_n^{po} = \sqrt{2}\sin \left[n\pi(1 + z/h)\right]\per
\eeq

%\section{Probing WKB}
%How accurate is the WKB approximate solution for the standard modes? To answer this questions,
%we first recall that the fundamental assumption in WKB is the slowly varying nature of $N^2(z)$.
%Second, the introduction  perturbation series \eqref{aseries} hinges on the smallness of the parameter
%$\ep$. Hence we expect the accuracy to increase with mode number. Specifically, the physical optics
%approximation truncates the series at first order, so the error decreases as $n^{-2}$.
%
%
%To verify the predictions above for the accuracy of the WKB solution, we consider an example with exponential stratification: $N^2(z) = N_0^2 \ee^{-\alpha z}$,
%where $N_0$ is the stratification frequency at the surface and $\alpha^{-1}$ is the e-folding depth (see figure 1). In this simple example,
%the standard modes can be calculated analytically in terms of Bessel functions (see LaCasce JPO 2012).
%Figure \ref{N2} shows the stratification profiles for two different e-folding scales: $\alpha=2$ and $\alpha=5$. With $\alpha=5$,
%the buoyancy frequency is strongly surface intensified as opposed to the slowly varying $\alpha=2$ profile. Indeed, the relative
%error of the WKB eigenvalue \eqref{kappan} as compared to the exact eigenvalue is more than 10 times smaller for $\alpha=2$
%than for $\alpha=5$ (see figure \ref{rerror}) --- the relative error in the first deformation wavenumber for $\alpha=2$ is spetacularly less than  $1\%$! As expected,
%the error decreases with modes number $n$ as $n^{-2}$. The eigenmodes are also well approximated by the WKB approximation (see figure \ref{eigenstructure}
%for the 4 gravest baroclinic modes with $\alpha=5$).  While there are some differences in amplitude, particularly at depth, the overall structure and zero-crossing depths
%are well captured by the WKB approximation.

%\begin{figure}[!ht]
%\label{N2}
%  \centering
%    \includegraphics[width=0.5\textwidth]{figs/N2.pdf}
%      \caption{The exponential stratification $N^2(z) = N_0^2 \ee^{-\alpha z}$ with $\alpha = 5$ and $\alpha=2$.}
%\end{figure}
%
%\begin{figure}[!ht]
%\label{rerror}
%  \centering
%    \includegraphics[width=0.5\textwidth]{figs/RelativeError.pdf}
%      \caption{The relative error in deformation wavenumber square (the eigenvalue) for exponential stratification $N^2(z) = N_0^2 \ee^{-\alpha z}$ with $\alpha = 5$ and $\alpha=2$. The magnitude of the error decreases with $\alpha$ ---  the buoyancy frequency is more slowly varying with $\alpha=2$.  The error decreases with mode
%      number as $n^{-2}$ ($-2$ slope in log$\times$log space).}
%\end{figure}
%
%\begin{figure}[!ht]
%\label{eigenstructure}
%  \centering
%    \includegraphics[width=0.9\textwidth]{figs/Eigenstructure.pdf}
%      \caption{The pressure modes for exponential stratification $N^2(z) = N_0^2 \ee^{-\alpha z}$ with $\alpha = 5$ calculated exactly (black) and using WKB (blue).}
%\end{figure}
%

\end{document}