%% LyX 2.2.0 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[english,notitlepage,showpacs,preprintnumbers,amsmath,amssymb,aps,nofootinbib,12pt]{revtex4-1}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\setcounter{secnumdepth}{3}
\usepackage{color}
\usepackage{verbatim}
\usepackage{units}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\PassOptionsToPackage{normalem}{ulem}
\usepackage{ulem}

\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage{microtype}
\usepackage{xspace}
\usepackage{amsfonts}
\usepackage{palatino}
\usepackage[]{algorithm2e}
\usepackage{MnSymbol}
\usepackage{bbm}
%\usepackage{hyperref}
%\usepackage[hyphenbreaks]{breakurl1}
\usepackage{url}
\usepackage{ragged2e}
\edef\UrlBreaks{\do\-\UrlBreaks}% after loading url or hyperref
\usepackage{accents} % needed for \underbar that's same as \bar (\underaccent)
\usepackage{microtype}

\usepackage{color}

\newcommand*{\mathcolor}{}
\def\mathcolor#1#{\mathcoloraux{#1}}
\newcommand*{\mathcoloraux}[3]{%
  \protect\leavevmode
  \begingroup
    \color#1{#2}#3%
  \endgroup
}

%% Set space of itemize environment
\usepackage{enumitem} % Used for setting height of itemize environments
\setlist[itemize]{topsep=0pt}%topsep=0pt

\newcommand{\hi}{$H_{\rm init}$\xspace}
\newcommand{\hf}{$H_{\rm final}$\xspace}

%% Set formatting of headers
\newcommand{\secspace}{\vspace{2mm}}

\newcommand{\summarysec}{\secspace\emph{\textbf{Summary}}}
\newcommand{\prossec}{\secspace\emph{\textbf{Pros}}}
\newcommand{\conssec}{\secspace\emph{\textbf{Cons}}}
\newcommand{\costsec}{\secspace\emph{\textbf{Cost}}}
\newcommand{\examplesec}{\secspace\emph{\textbf{Example}}}
\newcommand{\refsec}{\secspace\emph{\textbf{Bibliography}}}

\makeatother

\usepackage{babel}
\begin{document}

\title{Quadratization in Pseudo-Boolean Optimization and Adiabatic Quantum
Computing}

\author{Richard Tanburn$^{1,\,}$}
\email{richard.tanburn@hertford.ox.ac.uk}

\affiliation{$^{1}$Oxford University, Mathematical Institute, OX2 6GG, Oxford,
UK. }

\author{Nikesh S. Dattani$^{2,3}$}
\email{dattani.nike@gmail.com}
\affiliation{$^{2}$Oxford University, Physical and Theoretical Chemistry Laboratory, OX1 3BW, Oxford, UK,}

\begin{abstract}
There is a ridiculous amount of literature in so many different places, in communities that do not talk to each other, and do not even understand each other's language.
\end{abstract}

\maketitle

\title{\tableofcontents{}}

\section{Introduction}

\textbf{\emph{Every}} computation can be done by minimizing a Hamiltonian
of either one of the following forms:

\begin{equation}
H = \sum_{i}^{n} \left( \alpha_{i}z_{i}+\beta_{i}x_{i} \right) + \sum_{ij}^{n} \left( \alpha_{ij} z_{i}z_{j}+\beta_{ij}x_{i}x_{j} \right) \\\label{eq:XX+Z}
H = \sum_{i}^{n} \left( \alpha_{i}z_{i}+\beta_{i}x_{i} \right) + \sum_{ij}^{n} \left( \alpha_{ij} z_{i}z_{j}+\beta_{ij}x_{i}z_{j} \right), \\\label{eq:XZ+Z}

\end{equation}
where the $z$ and $x$ variables denote the Pauli matrices:
\begin{equation}
z\equiv\begin{pmatrix}1 & 0\\
0 & -1
\end{pmatrix},\,x\equiv\begin{pmatrix}0 & 1\\
1 & 0
\end{pmatrix},
\end{equation}
the $\alpha$ and $\beta$ coefficients are complex numbers; and the Appendix will teach any unfamiliar readers how to interpret this notation.

We know that every computation can be done this way because the minimization can be done by adiabatic quantum computation (AQC), and it has been proven \cite{Aharonov2008,Biamonte2008} that AQC can simulate any circuit-based quantum computation with overhead that grows at most polynomially with the size of the problem, and we know that circuit-based quantum computation can simulate any classical computation with at most polynomial overhead. %% Incorrect citation:  %Mizel2007
If we remove all the terms in Eq. \ref{eq:XX+Z} or Eq. \ref{eq:ZX+Z} that have $x$ operators, we get an Ising Hamiltonian that is quadratic:
\[
H=\sum_{i}^{n}a_{i}z_{i}+\sum_{ij}^{n}a_{ij}z_{i}z_{j},\label{eq:ZZ+Z}
\]
and we no longer know of any proof that \textbf{\emph{any}} computation can be done by minimizing such a Hamiltonian with only polynomial overhead compared to circuit-based quantum computation or even classical computation, but plenty of very interesting problems can still be formulated as the minimization or approximate minimization of a quadratic Ising Hamiltonian, such as neural network training \cite{Altaisky2016}, computerized image denoising \cite{Ishikawa2009,Ishikawa2011,Ishikawa2014,Anthony2015}, integer factorization \cite{Dattani2014}, and Ramsey number determination \cite{Gaitan2012,Bian2013}, just to name a few.
However unlike Eq. \ref{eq:XZ+Z}, plenty of devices that can minimize Ising Hamiltonians already exist, and with further restrictions on the $a$ coefficients, D-Wave has made devices with $n=2000$, and this number has roughly doubled every 14 months since the first 1-qubit demonstration in 2003, a phenomenon analogous to Moore's law of classical computer growth, which has become known as Rose's Law.

Furthermore,\textbf{\emph{ no classical computer has ever been able to minimize certain quadratic Ising Hamiltonians faster than the D-Wave machines to date}} \cite{Denchev2016,Mandra2016}, so being able to turn computations into the form of Eq. \ref{eq:ZZ+Z} appears to be promising in terms of demonstrating the first useful application of quantum supremacy (which is the term used for quantum devices outperforming classical computation devices).
Moreover, for problems like neural networks and computerized image denoising, the best known classical computation algorithms also work by turning the problems into minimizations of Ising Hamiltonians, so even if you are happy with continuing to only use classical computer and have no interest in using quantum annealing devices, turning a problem into a quadratic Ising Hamiltonian minimization problem can be very powerful for some computations.

For neural networks, image denoising, integer factorization, and Ramsey number determination, it is rather easy to turn the problem into the form:

\begin{equation}
H=\sum_{i}^{n}\alpha_{i}z_{i}+\sum_{ij}^{n}\alpha_{ij}z_{i}z_{j}+\sum_{ijk}^{n}\alpha_{ijk}z_{i}z_{j}z_{k}+\sum_{ijkl}^{n}\alpha_{ijkl}z_{i}z_{j}z_{k}z_{l}\ldots,\label{eq:Z+ZZ+ZZZ+ZZZZ...}
\end{equation}
but then \textbf{\emph{quadratizing}} Eq. \ref{eq:Z+ZZ+ZZZ+ZZZZ...} into the quadratic Ising form often requires the introduction of auxiliary variables, and since minimizing Eq. \ref{eq:Z+ZZ+ZZZ+ZZZZ...} often has cost $\mathcal{O}(2^{n})$, it is often extremely desirable to do the quadratization with \textbf{\emph{as few auxiliary variables as possible}}.
Apart from quadratizing with minimum number of variables, it is also often desirable to reduce the number of non-zero $\alpha$ coefficients, to keep the non-zero $\alpha$ coefficients bounded or with specific values, to reduce the number of positive (non-submodular) $\alpha$ coefficients, to reduce the spectral ratio of the Hamiltonian (`maximum energy minus
minimum energy' divided by `energy of the second minimum minus the energy of the global minimum'), and to reduce the number of energy levels close to the global minimum.
Adjusting the energy landscape in order to accomplish all of these things apart from reducing the number of auxiliary variables needed has been termed Energy Landscape Manipulation (ELM) which is an entirely separate topic, sometimes even more important than quadratizing with as few auxiliary variables as possible, nonetheless this Review simply focuses on methods for the latter aim.

It has been shown in \cite{Anthony2015} that a general function of the form Eq. \ref{eq:Z+ZZ+ZZZ+ZZZZ...} with degree $k$, can be quadratized using $O(n^{k/2})$ auxiliary variables.
However, it is often possible to quadratize with far fewer auxiliary variables (for example when the auxiliary variables for quadratizing one term are reused to quadratize other terms that have some of the same variables in them) or to quadratize without any auxiliaries at all (ex. if a Groebner basis can be found with all basis functions being quadratic, or if some symmetries in the Hamiltonian can be found that make it possible to quadratize without auxiliaries).

\begin{comment}
Also shown in \cite{Ishikawa2011} that a PSB in $n$ variables requires at most $2^{n}-1$ auxiliary variables (by representing it as a function of degree $n$).

Positive quadratic terms (non-submodular), particularly with large positive coefficients, are hard for a lot of reasons, classically (Ishikawa TGBMM....) \cite{Ishikawa2011}.
\end{comment}

\part{Hamiltonians with only $z$ terms (pseudo-Boolean functions)}

\section{Methods that introduce ZERO auxiliary variables}

\subsection{Groebner Bases}

\begin{comment}
% Nike's old summary
A Groebner basis is a set of equations representing the zeros of a polynomial (e.g. of the form Eq. \ref{eq:Z+ZZ+ZZZ+ZZZZ...}) such that the number of variables is the same, and the zeros of Eq. \ref{eq:Z+ZZ+ZZZ+ZZZZ...} are the same as the zeros of all equations of the Groebner basis.
If a Groebner basis can be found such that all equations are quadratic, then quadratization of Eq. \ref{eq:Z+ZZ+ZZZ+ZZZZ...} is as simple as finding the Groebner basis.

\begin{comment}
Nike, this is NOT true.
Once we have the Groebner basis, we still need a single non-negative expression to minimize.
This involves finding appropriate coefficients of the equations to add together (non-trivial and what they do in the 1Qbit paper) OR squaring each one, which gives a quartic.
\end{comment}

\begin{comment}
Use the multivariate extension of Gaussian elimination to find a different set of equations which have the same vanishing set.
It has been shown these can be used to reduce and embed factorisations of all bi-primes up to 200,000 \cite{Dridi2016}.
Some work has been done in the field of ``boolean Groebner bases'', but these consider bases of a boolean ring over $\mathbb{F}_{2}$ rather than $\mathbb{Q}$.
\end{comment}

%% Old description
\begin{comment}
\textcolor{red}{Richard: too much algebra here. People come from different
backgrounds. Some people don't know what rings are, and some people
get scared when they see fancy symbols like $\mathcal{V}$. It should
be possible to describe this to A-level students because that way
we know everyone (chemists, physicists, engineers, computer scientsists,
etc.) will understand it. I guess I already did this in a way that
A-level students would understand, in the ``summary section''. For
``descriptions'' I envision that we explain exactly how to DO the
methods, and for Groebner bases, I guess this would be equivalent
to listing the known algorithms (such as Buchberger's) and known codes
available. I guess another description that could be added is the
method in the 1Qbit paper, where they have a ``max\_cutoff'' and
a ``min\_cutoff'' and Groebnerized everything in between there,
or something like that.}

Instead of solving the equations $f_{1}=f_{2}=...=f_{n}=0$ directly,
Groebner bases consider the points on which they vanish, also known
as the \emph{algebraic variety} $\mathcal{V}(f_{1},...,f_{n})$. Groebner
bases are a 'pleasant' generating set for this variety.

This is done by first defining a monomial ordering on the polynomial
ring $F[z_{1},...,z_{n}]$, chosen so that higher order mononials
are considered 'bigger' than low order monomials. Monomials of the
same degree are sorted by the lexicographic ordering of the variables.
Then define the leading term of a polynomial $f$ with respect to
the monomial ordering to be $\mathrm{LT}(f)$, the largest monomial
of $f$. Then $g_{1},...,g_{m}$ is a Grobner basis if $\mathcal{V}(f_{1},...,f_{n})$=$\mathcal{V}(g_{1},...,g_{m})$
(they have the same vanishing set) and for every function $f$ in
the ideal of $\left\langle f_{1},...f_{n}\right\rangle $, we have
that the leading term of $f$ is divisible by the leading term of
$g_{i}$ for some $i$.

Grobner bases are very useful because they allow computation of remainders,
using the multivariate division algorithm. They are useful in this
context since the polynomials of the Grobner basis will have smaller
degrees than our original function, reducing the need for reduction
by other means.
\end{comment}

\summarysec

Given a set of polynomials, a Groebner basis is another set of polynomials that have exactly the same zeros.
The advantage of a Groebner basis is it has nicer algebraic properties than the original equations, in particular they tend to have smaller degree polynomials.
The algorithms for calculating Groebner bases are generalisations of Euclid's algorithm for the polynomial greatest common divisor.

Work has been done in the field of 'Boolean Groebner bases', but while the variables are Boolean the coefficients of the functions are in $\mathbb{F}_{2}$ rather than $\mathbb{Q}$.

\costsec
\begin{itemize}
\item $0$ auxiliary variables needed,
\item $2^{2^{\mathcal{O}(n)}}$ in general, $\mathcal{O}(d^{n^{2}})$ if the zeros of the equations form a set of discrete points, where $d$ is the degree of the polynomial and $n$ is the number of variables \cite{Bardet2002}.
\end{itemize}

\prossec
\begin{itemize}
\item No auxiliary variables needed.
\item General method, which can be used for other rings, fields or types of variables.
\end{itemize}

\conssec
\begin{itemize}
\item Best algorithms for finding Groebner bases scale double exponentially in $n$.
\item Only works for Hamiltonians whose minimization corresponds to solving systems of discrete equations.
\end{itemize}

\examplesec

Consider the following pair of equations:

\[
x y z w + x z + y w - z = x + x y + z - 2 = 0.
\]

Feeding these to Mathematica's ${\tt GroebnerBasis}$ function, along with the binarizing $x(x-1)=\ldots=w(w-1)=0$ constraints, gives a Groebner basis:

\[
\left\{ w z - w, y + z - 1, x - 1 \right\}.
\]

From this we can immediately read off the solutions $x=1$, $y=1-z$ and reduce the problem to $wz-w=0$. Solving this gives a final solution set of: $(x, y, z, w) = (1, 0, 1, 0), (1, 0, 1, 1), (1, 1, 0, 0)$.

\refsec
\begin{itemize}
%\item Standard text on Computational Algebraic Geometry: \cite{Cox2007}.
\item Reduction and embedding of factorizations of all bi-primes up to $200,000$: \cite{Dridi2016}.
\end{itemize}

\begin{comment}
To quadratize the Hamiltonian:
\[
H_{4{\rm -local}}=(z_{1}z_{2}-z_{3}z_{4}-1)^{2},
\]
we first linearize the part that is being squared. In Mathematica,
the ${\tt GroebnerBasis}$ function gives us:

Then when we square it we get a quadratic function:

\[
H_{2{\rm -local}}=1-2z_{1}-2z_{2}+3z_{3}+3z_{4}-2z_{3}z_{4}.
\]
In both cases, the only global minima occur when:

\begin{equation}
(z_{3,}z_{4})=1,\,z_{1}\,\text{or}\,z_{2}=0.
\end{equation}

\textcolor{red}{Wait, this is far from true!}
\end{comment}

\subsection{Deduction Reduction (Deduc-reduc)}

\summarysec

We look for \emph{deductions} (e.g. $z_{1}z_{2}=0$) that hold at the global minimum.
These can be found by \emph{a priori} knowledge of the given problem, or by enumerating solutions of a small subset of the variables.
We can then substitute high-order terms using the low-order terms of the deduction, and add on a penalty term to preserve the ground states \cite{Tanburn2015c}.

\costsec
\begin{itemize}
\item $0$ auxiliary variables needed.%  Given a deduction, the reduction time is proportional to the number of terms in the Hamiltonian and is negligible. (but this is true of all the other reducs too)
\item The computational cost of the search for deductions is difficult to estimate.
The approximate worst-case complexity is $\mathcal{O}(n^{d+1}2^{m})$ where $m$ is the number of variables in a 'small' problem, $n$ is the total number of qubits and $d$ is the maximum degree of deductions we are searching for.
We suggest $10 \le m \le 20$, so that a small problem involves checking roughly $1,000$ to $1,000,000$ states, and $d=2$.
See the appendix for more details.
\end{itemize}

\prossec
\begin{itemize}
\item No auxiliary variables needed.
%\item Able to use extra information about a given problem.
\end{itemize}

\conssec
\begin{itemize}
\item When deductions cannot be determined naturally (as in the Ramsey number determination problem, see Example \ref{subsec:Example_Ramsey_deduc_reduc}), deductions need to be found by `brute force', which scales exponentially with respect to $m$.
For highly connected systems (systems with a large number of non-zero $a$ coefficients), the value of $m$ required to find even one deduction can be prohibitively large.
%\item Deductions do not always exist, or are too hard to find.
\end{itemize}

\examplesec

\begin{comment}
Examples are difficult to illustrate in a paper, since they involve searching for patterns in exhaustive searches.
\end{comment}
Consider the Hamiltonian:
\[
H_{4{\rm -local}}=z_{1}z_{2}(10+z_{3}+z_{3}z_{4})+z_{1}(z_{3}-3)+z_{2}(z_{3}-2z_{3}-z_{4}-1)+F(x_{3},x_{4},x_{5},\ldots,x_{N})
\]
 where $F$ is any polynomial in $z_{i}$ for $3\le i$.

Since the $10$ coefficient of $z_{1}z_{2}$ is greater than the sum of all of the other coefficients involving $z_{1}$ or $z_{2}$, it must be the case that $z_{1}z_{2}=0$.
Specifically, for the 4 assignments of $(z_{3},z_{4})$, we see that $z_{1}z_{2}=0$ at every minimum of $H_{4{\rm -local}}-F$.

Using deduc-reduc we have:
\[
H_{2{\rm -local}}=12z_{1}z_{2}+z_{1}(z_{3}-3)+z_{2}(z_{3}-2z_{3}-z_{4}-1)+F(x_{3},x_{4},x_{5},\ldots,x_{N})
\]

which has the same global minima as $H_{4-local}$ but one fewer quartic and one fewer cubic term.

\refsec
\begin{itemize}
\item Original paper, with application to integer factorization: \cite{Tanburn2015c}.
\end{itemize}

\subsection{ELC Reduction}

\summarysec

An Excludable Local Configuration (ELC) is a partial assignment of variables that cannot possibly give the global minimum.
We can then add on a term that corresponds to the energy of this ELC.
In practice we can eliminate all monomials with a variable in which a variable is set to 0, and reduce any variable set to 1.
Given a general Hamiltonian we can try to find ELCs by enumerating solutions of a small subset of the problem \cite{Ishikawa2014}.

\costsec
\begin{itemize}
\item $0$ auxiliary variables needed.
\item $\mathcal{O}\left(2^{m}\binom{n}{m}\right)$ operations required to enumerate all possible cases for all possible subsets of size $m \le n$ variables.
\item Approximate methods exist which have been shown to be much faster and give good approximations to the global minimum \cite{Ishikawa2014}.
\end{itemize}

\prossec
\begin{itemize}
\item No auxiliary variables needed.
\end{itemize}

\conssec
\begin{itemize}
\item ELCs need to be found by `brute force', which scales exponentially with respect to $m$.
\item ELCs do not always exist.
\end{itemize}

\examplesec

Consider the Hamiltonian:
\[
H_{{\rm 3-local}}=z_{1}z_{2}+z_{2}z_{3}+z_{3}z_{4}-4z_{1}z_{2}z_{3}.
\]
If $z_{1}z_{2}z_{3}=0$, no assignment of our variables will we be able to reach a lower energy than if $z_{1}z_{2}z_{3}=1$.
Hence $(z_{1},z_{2},z_{3})=(1,0,0)$ is a Local Excludable Configuration (ELC) and we can form the polynomial:
\[
H_{2\text{-local}}=H_{{\rm 3-local}}+4z_{1}(1-z_{2})(1-z_{3})=z_{1}z_{2}+z_{2}z_{3}+z_{3}z_{4}+4z_{1}-4z_{1}z_{2}-4z_{1}z_{3}.
\]
In both cases, the only global minima occur when:

\refsec
\begin{itemize}
\item Original paper and application to computerized image denoising: \cite{Ishikawa2014}.
\end{itemize}

\subsection{Split Reduction}

\summarysec

It has been shown in \cite{Okada2015} that, if multiple runs of a minimization algorithm is permitted, it is possible to reduce a lot of the problem by conditioning on the most connected variables.
We call each of these operations a \emph{split}.

\costsec

Exponential in the number of splits, as the number of problems to solve doubles with every split.

\prossec
\begin{itemize}
\item This method can be applied to any problem and can be very effective on problems with a few very connected variables.
\end{itemize}

\conssec
\begin{itemize}
\item Exponential cost in the worst case.
\end{itemize}

\examplesec

Consider the simple objective function
\[
H=1+z_{1}z_{2}z_{5}+z_{1}z_{6}z_{7}z_{8}+z_{3}z_{4}z_{8}-z_{1}z_{3}z_{4}.
\]
In order to quadratise $H$, we first have to choose a variable to split over.
In this case $z_{1}$ is the obvious choice since it is present in the most terms and contributes to the quartic term.

We then obtain two different problems:
\begin{eqnarray*}
H_{0} & = & 1+z_{3}z_{4}z_{8}\\
H_{1} & = & 1+z_{2}z_{5}+z_{6}z_{7}z_{8}+z_{3}z_{4}z_{8}-z_{3}z_{4}.
\end{eqnarray*}

At this point, we could split $H_{0}$ again and solve it entirely, or use a qubit we saved in the previous split to quadratize our only problem.

To solve $H_{1}$, we can split again on $z_{8}$, resulting in problems:
\begin{eqnarray*}
H_{1,0} & = & 1+z_{2}z_{5}+z_{6}z_{7}\\
H_{1,1} & = & 1+z_{2}z_{5}+z_{3}z_{4}.
\end{eqnarray*}
Now both of these problems are quadratic.
Hence we have reduced our original, hard problem into 3 easy problems, requiring only 2 extra runs of our minimization algorithm, and without needing any auxiliary variables.

\refsec
\begin{itemize}
\item Original paper and application to Ramsey number calculation: \cite{Okada2015}.
\end{itemize}

\section{Methods that introduce auxiliary variables to quadratize a SINGLE
term}

\subsection{Negative Term Reduction \label{sec:Negative-Monomial-Reduction}}

\summarysec

For a negative term $-z_{1}z_{2}...z_{k}$, introduce a single auxiliary variable $a$ and make the substitution:
\[
-z_{1}z_{2}...z_{k} = \min_a \left\{ (n-1-\sum z_{i})a \right\}.
\]

\costsec
\begin{itemize}
\item 1 auxiliary variable for each $k$-local term.
\end{itemize}

\prossec
\begin{itemize}
\item All resulting quadratic terms are submodular (have negative coefficients).
\item Can reduce arbitrary order terms with only 1 auxiliary.
\item Can be generalised so that one variable can be made to work for multiple terms. (I can't find anyone saying this, but I can prove it. Shall we put it in an appendix?)
\end{itemize}

\conssec
\begin{itemize}
\item Only works for negative terms.
\end{itemize}

\examplesec

\begin{align*}
H_{{\rm 6-local}} & =-z_{1}z_{2}z_{3}z_{4}z_{5}z_{6},
\end{align*}
has a unique minimum energy of -1 when all $z$'s are 1.

\begin{equation}
H_{{\rm 2-local}}=5a-z_{1}a-z_{2}a-z_{3}a-z_{4}a-z_{5}a-z_{6}a
\end{equation}
has the same unique minimum energy, and it occurs at the same place (all $z$'s being 1), with $a=1$.

\examplesec

\begin{align*}
H_{{\rm 5-local}} & =-z_{1}z_{2}z_{3}z_{4}z_{5}-z_{1}z_{2}z_{3}z_{4}z_{6},
\end{align*}
has a unique minimum energy of -2 when all $z$'s are 1.

\begin{equation}
H_{{\rm 2-local}}=(3-z_{1}-z_{2}-z_{3}-z_{4})(z_{5}+z_{6})a
\end{equation}
has the same unique minimum energy, and it occurs at the same place (all $z$'s being 1),
with $a=1$.

\refsec
\begin{itemize}
\item Original paper: \cite{Freedman2005}.
\item Discussion: \cite{Ishikawa2011}, \cite{Anthony2015}.
\end{itemize}

\subsection{Positive Term Reduction}

\summarysec

By considering the negated literals $\bar{z}_{i}=1-z_{i}$, we recursively apply the previous method to $z_{1}z_{2}\ldots z_{k}=-\bar{z}_{1}z_{2}\ldots z_{k}+z_{2}z_{3}\ldots z_{k}$.
The final identity is:
\[
z_{1}z_{2}\ldots z_{k}=\min_{a}\big\{\sum_{i=1}^{k-2}a_{i}(k-i-1+z_{i}-\sum_{j=i+1}^{k}z_{j})\big\}+z_{k-1}z_{k}
\]

\costsec
\begin{itemize}
\item $k-2$ auxiliary variables for each $k$-local term.
\end{itemize}

\prossec
\begin{itemize}
\item Works for positive monomials.
\end{itemize}

\conssec
\begin{itemize}
\item $k-1$ non-submodular quadratic terms.
\end{itemize}

\examplesec

\begin{eqnarray*}
z_{1}z_{2}z_{3}z_{4} & = & \min_{a}{a_{1}(2+z_{1}-z_{2}-z_{3}-z_{4})+a_{2}(1+z_{2}-z_{3}-z_{4})}+z_{3}z_{4}
\end{eqnarray*}

\refsec
\begin{itemize}
\item Summary: \cite{Boros2014}.
\end{itemize}

\begin{comment}
By flipping and applying \ref{sec:Negative-Monomial-Reduction} alternatively, we get a nice way to reduce a quartic using only 2 variables and with only 2 positive terms and much less connectivity:

\begin{eqnarray*}
z_{1}z_{2}z_{3}z_{4} & \mapsto & z_{2}z_{3}z_{4}-\bar{z}_{1}z_{2}z_{3}z_{4}\\
 & \mapsto & z_{2}z_{3}z_{4}+\big(3a_{1}-a_{1}(\bar{z}_{1}+z_{2}+z_{3}+z_{4})\big)\\
 & \mapsto & z_{3}z_{4}-\bar{z}_{2}z_{3}z_{4}+\big(3a_{1}-a_{1}(\bar{z}_{1}+1-\bar{z}_{2}+z_{3}+z_{4})\big)\\
 & \mapsto & z_{3}z_{4}+\big(2a_{2}-a_{2}(\bar{z}_{2}+z_{3}+z_{4}\big)\big)+\big(3a_{1}-a_{1}(\bar{z}_{1}+1-\bar{z}_{2}+z_{3}+z_{4})\big)\\
 & \mapsto & z_{3}z_{4}+a_{2}+a_{2}z_{2}-a_{2}z_{3}-a_{2}z_{4}+2a_{1}+a_{1}z_{1}-a_{1}z_{2}-a_{1}z_{3}-a_{1}z_{4}
\end{eqnarray*}
\end{comment}

\subsection{Ishikawa's Symmetric Reduction (Positive Term Reduction)}

\summarysec

This method rewrites a positive monomial using symmetric polynomials, so all possible quadratic terms are produced and they are all non-submodular:
\[
z_{1}...z_{k} = \min_{a_1, \ldots, a_{n_k}} \left\{ \sum_{i=1}^{n_{k}}a_{i}(c_{i,d}(-\sum_{j=1}^{k}z_{j}+2i)-1)+\sum_{i<j}z_{i}z_{j} \right\}
\]
where $n_{k}=\left\lfloor \frac{k-1}{2}\right\rfloor $ and $c_{i,k}=\begin{cases}
1, & i=n_{d}\text{ and }k\text{ is odd,}\\
2, & \text{else.}
\end{cases}$

\costsec
\begin{itemize}
\item $\left\lfloor \frac{k-1}{2}\right\rfloor $ auxiliary variables for each $k$-order term
\end{itemize}

\prossec
\begin{itemize}
\item Works for positive monomials.
About half as many auxiliary variables for each $k$-order term as the previous method.
\end{itemize}

\conssec
\begin{itemize}
\item $\mathcal{O}(k^{2})$ quadratic terms are created, which may make chimerization more costly.
\item $\frac{k(k-1)}{2}$ non-submodular terms.
\item Worse than the previous method for quartics, with respect to submodularity.
\end{itemize}

\examplesec
\begin{eqnarray*}
z_{1}z_{2}z_{3}z_{4} & = & \min_{a}(3-2z_{1}-2z_{2}-2z_{3}-2z_{4})a+z_{1}z_{2}+z_{1}z_{3}+z_{1}z_{4}+z_{2}z_{3}+z_{2}z_{4}+z_{3}z_{4}
\end{eqnarray*}

\refsec
\begin{itemize}
\item Original paper and application to image denoising: \cite{Ishikawa2011}.
\end{itemize}

\subsection{Asymmetric Reduction}

\summarysec

Similar to other methods of reducing one term, this method can reduce a positive cubic monomial into quadratic terms using only one auxiliary variable, while introducing fewer non-submodular terms than the symmetric version.

\costsec

1 auxiliary qubit per positive cubic term.

\prossec
\begin{itemize}
\item Works on positive monomials.
\item Fewer non-submodular terms than Ishikawa Reduction.
\end{itemize}

\conssec
\begin{itemize}
\item Only been shown to work for cubics.
\end{itemize}

\examplesec

\[
z_{1}z_{2}z_{3}= \min_a \left\{ a-z_{2}a-z_{3}a+z_{1}a+z_{2}z_{3} \right\}
\]

\refsec
\begin{itemize}
\item Original paper and application to computer vision: \cite{Gallagher2011}.
\end{itemize}

\subsection{Bit-flipping}

\summarysec

For any variable $z$, we can consider the negation $\bar{z}=1-z$.
The process of exchanging $z$ for $\bar{z}$ is called \emph{flipping}.
Using bit-flipping, an arbitrary function in $n$ variables can be represented using at most $2^{(n-2)}(n-3)+1$ variables, though this is a gross overestimate.

Can be used in many different ways:
\begin{enumerate}
\item Flipping positive terms and using \ref{sec:Negative-Monomial-Reduction}, recursively;
\item For $\alpha<0$, we can reduce $\alpha\bar{z}_{1}\bar{z}_{2}...\bar{z}_{k}$ very efficiently to submodular form using \ref{sec:Negative-Monomial-Reduction}.
A generalised version exists for arbitrary combinations of flips in the monomial which makes reduction entirely submodular \cite{Ishikawa2011};
\item When we have quadratized we can minimise the number of non-submodular terms by flipping;
\item We can make use of both $z_{i}$ and $\bar{z}_{i}$ in the same Hamiltonian by adding on a sufficiently large penalty term: $\lambda(z_{i}+\bar{z}_{i}-1)^{2}=\lambda(1+2z_{i}\bar{z}_{i}-z_{i}-\bar{z}_{i})$.
This is similar to the ideas in Substition Reduction or deduc-reduc.
In this way, given a quadratic in $n$ variables we can make sure it only has at most $n$ nonsubmodular terms if we are willing to use the extra $n$ negation variables as well (so we have $2n$ variables in total). (This is my own claim. Is it worth keeping?)
\end{enumerate}

\costsec
None, as replacing $z_{i}$ with it's negation $\bar{z}_{i}$ costs nothing except a trivial symbolic expansion.

\prossec
\begin{itemize}
\item Cheap and effective way of improving submodularity.
\item Can be used to combine terms in clever ways, making other methods more efficient.
\end{itemize}

\conssec
\begin{itemize}
\item Unless form of the Hamiltonian is known, spotting these 'factorizations' using negations is difficult.
\item If we want to use $z$ and $\bar{z}$ we need an auxiliary variable.
\end{itemize}

\examplesec

Consider
\begin{eqnarray*}
H & = & 3z_{1}z_{2}+z_{2}z_{3}+2z_{1}z_{4}-4z_{2}z_{4}\protect\\
 & = & -3z_{1}\bar{z}_{2}-\bar{z}_{2}z_{3}-2z_{1}\bar{z}_{4}-\bar{z}_{2}\bar{z}_{4}+5z_{1}+z_{3}+4\bar{z}_{2}+4\bar{z}_{4}-4.
\end{eqnarray*}
The first expression is highly non-submodular while the second is entirely submodular.

\refsec
\begin{itemize}
\item Original paper: \cite{Ishikawa2011}.
\end{itemize}

\section{Methods that introduce auxiliary variables to quadratize MULTIPLE terms with the SAME auxiliaries}

\subsection{Reduction by Substitution}

\summarysec

Pick a variable pair $z_{i},z_{j}$ and substitute $z_{i}z_{j}$ for new auxiliary variable $a_{i,j}$.
Enforce equality in the ground states by adding some scalar multiple of $z_{i}z_{j}-2z_{i}a_{i,j}-2z_{i}a_{i,j}+3a_{i,j}$ or similar.

\costsec
\begin{itemize}
\item 1 auxiliary variable per reduction.
\end{itemize}

\prossec
\begin{itemize}
\item Variable can be used across the entire Hamiltonian, reducing many terms at once.
\item Simple.
\end{itemize}

\conssec
\begin{itemize}
\item Inefficient for single terms as it introduces many of variables.
\item Introduces quadratic terms with large positive coefficients, making them highly non-submodular.
\item Determining optimal substitutions is expensive.
\end{itemize}

\examplesec

We pick the pair $(z_{1},z_{2})$ and combine.

\[
z_{1}z_{2}z_{3}+z_{1}z_{2}z_{4}\mapsto z_{3}a+z_{4}a+z_{1}z_{2}-2z_{1}a-2z_{1}a+3a
\]

\refsec
\begin{itemize}
\item Original paper: \cite{Rosenberg1975}
\end{itemize}

\subsection{FGBZ Reduction (Fix-Gruber-Boros-Zabih)}

\summarysec

Here we consider a set $C$ of variables which occur in multiple monomials throughout the Hamiltonian.
Each application 'rips out' this common component from each term \cite{Fix2011}\cite{Boros2014}.

Let $\mathcal{H}$ be a set of monomials, where $C \subseteq H$ for each $H\in\mathcal{H}$ and each monomial $H$ has a weight $\alpha_{H}$.
The algorithm comes in 2 parts: when all $\alpha_{H}>0$ and when all $\alpha_{H}<0$. Combining the 2 gives the final method:

\begin{enumerate}
\item $\alpha_{H}>0$
\[
\sum_{H\in\mathcal{H}}\alpha_{H}\prod_{j\in H}z_{j}=\min_{a}(\sum_{H\in\mathcal{H}}\alpha_{H})a\prod_{j\in C}z_{j}+\sum_{H\in\mathcal{H}}\alpha_{H}(1-a)\prod_{j\in H\setminus C}z_{j}
\]
\item $\alpha_{H}<0$
\[
\sum_{H\in\mathcal{H}}\alpha_{H}\prod_{j\in H}z_{j}=\min_{a}\sum_{H\in\mathcal{H}}\alpha_{H}(1-\prod_{j\in C}z_{j}-\prod_{j\in H\setminus C}z_{j})a
\]
\end{enumerate}

\costsec
\begin{itemize}

\item One auxiliary variable per application.
\item In combination with \ref{sec:Negative-Monomial-Reduction}, they can be used to make an algorithm which can reduce $t$ positive monomials of degree $d$ in $n$ variables using $n+t(d-1)$ auxiliary variables in the worst case.
\end{itemize}

\prossec
\begin{itemize}
\item Can reduce the connectivity of a Hamiltonian, as it breaks interactions between qubits.
\end{itemize}

\conssec
\begin{itemize}
\item Positive method converts positive terms into negative ones of same order rather than reducing them, though these can then be reduced more easily.
\item $\alpha_{H}<0$ method only works for $|C|>1$, and cannot quadratize cubic terms.
\end{itemize}

\examplesec

First let $C=z_{1}$ and use the positive weight version:
\begin{eqnarray*}
z_{1}z_{2}z_{3}+z_{1}z_{2}z_{4} & \mapsto & 2a_{1}z_{1}+(1-a_{1})z_{2}z_{3}+(1-a_{1})z_{2}z_{4}\\
 & = & 2a_{1}z_{1}+z_{2}z_{3}+z_{2}z_{4}-a_{1}z_{2}z_{3}-a_{1}z_{2}z_{4}
\end{eqnarray*}
now we can use \ref{sec:Negative-Monomial-Reduction}:

\begin{eqnarray*}
-a_{1}z_{2}z_{3}-a_{1}z_{2}z_{4} & \mapsto & 2a_{2}-a_{1}a_{2}-a_{2}z_{2}-a_{2}z_{3}+2a_{2}-a_{1}a_{2}-a_{2}z_{2}-a_{2}z_{4}\\
 & = & 4a_{2}-2a_{1}a_{2}-2a_{2}z_{2}-a_{2}z_{3}-a_{2}z_{4}.
\end{eqnarray*}

\refsec
\begin{itemize}
\item Original paper and application to image denoising: \citep{Fix2011}.
\end{itemize}

\begin{comment}

\subsection{Generalized roof duality}

(only 1 extra qubit, but only works for up to 5-qubit terms.)

Nike, where did you get the above from? When I search for this, with
the relevant authors, I only find stuff on QPBO. I've spent a while
reading papers on QPBO (fascinating stuff, very impressive and in
some ways similar to what we've been trying/will try to do. Is the
quantum community aware of their software??). I don't know what roof
duality you're referring to.

\subsection{Generalized Roof Duality (QPBO)}

\summarysec

Algorithm that takes a quadratic Hamiltonian and tries to perform as much of the optimization as possible.

\costsec

For computer image problems, it can be used with the above methods to optimize most of the image in seconds/minutes \cite{Ishikawa2014,Fix2011,Ishikawa2011}.
\end{comment}

\section{Methods that reproduce the full spectrum}

In all the above, we take advantage of the fact that we just want the correct state and we don't care about anything else.
This gave us the freedom to do all sorts of things to the Hamiltonian, as long as we keep the ground state the same.
What if we want to quadratize a Hamiltonian while preserving the whole spectrum?
%LHZ scheme and Paul Warburton's methods.

\section{Strategies for combining methods}

Should look at ORI graph in \cite{Gallagher2011}

\part{Hamiltonians with both $z$ \& $x$ terms (general quantum Hamiltonians)}

In the above we only have $z$ terms.
If we have both $z$ and $x$ then quadratization methods have a rich history, dating back to the perturbative gadgets that were used by Kitaev and his camp for proving that the $2$-local Hamiltonian problem is QMA complete and that AQC is equiavent to circuit-based quantum computing.
Jacob Biamonte came up with various schemes for quadratizing general spin Hamiltonians with only 1 auxiliary qubit for each reduction (quintic to quartic, quartic to cubic, cubic to quadratic, etc.). Below we show how the ideas above such as FGBZ can be generalized to the case where there's both $z$ and $x$ terms. ``auxiliary qubit recycling'', where the auxiliary qubit used to substitute one term can be reused to reduce other terms in the Hamiltonian.

\section{Recursive gadget reduction (original)}

Kitaev. klocal -> (k-1)loal -> (k-2)local -> ... -> 2-local (1 auxiliary each time)

\section{Recursive gadget reduction (better)}

Oliviera & Terhal (2005), Cao et al (2013), Bravyi et al (2008), Duan et al (2011), Babbush et al (2013)  klocal -> (k-1)loal -> (k-2)local -> ... -> 2-local (1 auxiliary each time)

\section{One-step gadget reduction}

Jordan \& Fahri

\section{Numerical}

Panagiotis (2017) https://arxiv.org/pdf/1706.03637.pdf

\section{Methods that reproduce the full spectrum}

\part{Appendix}

\section{Further Examples}

\examplesec \label{subsec:Example_Ramsey_deduc_reduc}
Here we show how deductions can arise naturally from the Ramsey number problem.
Consider $\mathbb{\mathcal{R}}(4,3)$ with $N=4$ nodes.
Consider a Hamiltonian:
\[
H = (1-z_{12})(1-z_{13})(1-z_{23})+\ldots+(1-z_{23})(1-z_{24})(1-z_{34})+ z_{12}z_{13}z_{14}z_{23}z_{24}z_{34}.
\]

\begin{comment}
We should assume there are no 3-independent sets, so we have deductions:
$(1-z_{ij})(1-z_{ik})(1-z_{jk})=0$, for each $i,j,k$.
\end{comment}
See \cite{Okada2015} for full details of how we arrive at this Hamiltonian.

Since we are assuming we have no 3-independent sets, we know that
$(1-z_{12})(1-z_{13})(1-z_{23})=0$, so $z_{12}z_{13}z_{23}=z_{12}z_{13}+z_{12}z_{23}+z_{13}z_{23}-z_{12}-z_{13}-z_{23}+1$.
This will be our deduction.

Using deduc-reduc we can substitute this into our 6-local term to get:
\begin{eqnarray*}
H & = & 2(1-z_{12})(1-z_{13})(1-z_{23})+\ldots+(1-z_{23})(1-z_{24})(1-z_{34})+\\
 &  & z_{14}z_{24}z_{34}(z_{12}z_{13}+z_{12}z_{23}+z_{13}z_{23}-z_{12}-z_{13}-z_{23}+1).
\end{eqnarray*}

We could repeat this process to remove all 5- and 4-local terms without adding any auxiliary qubits.
Note in this case the error terms added by deduc-reduc already appear in our Hamiltonian.

\section{Notation}

The left Kronecker product by a $2\times2$ identity matrix is implied by Eqs. \eqref{XX+Z} and \eqref{ZX+Z} in the following way for qubit operators $q\in\{z,x\}$, assuming $i<j$:

\begin{align}
q_{i} & =\mathbf{1}^{\otimes i-1}q\mathbf{1}^{\otimes(N-i+1)}\\
q_{i}\bar{q}_{j} & =\mathbf{1}^{\otimes i-1}q\mathbf{1}^{\otimes(j-1+i)}\bar{q}\mathbf{1}^{\otimes(N-j+1)}.
\end{align}
Thinking in this way, with this notation might take some time to get
used to, but tens of thousands of people are comfortable thinking
this way (including any undergraduate student after a 1-semester quantum
computing course). You can now see that $H$ is a $2^{N}\times2^{N}$
matrix with elements that are complex numbers. ``Minimizing the Hamiltonian''
just means finding the eigenvector of this matrix with lowest eigenvalue.
On a classical computer, the cost of finding this eigenvector is the
cost of diagonalizing the matrix: $\mathcal{O}(2^{3N})$, but undergraduate
level quantum mechanics tells us that any physical system's state
(wavefunction, $\psi_{n}$) is an eigenvector of a Hamiltonian and
the eigenvalue $E_{n}$ is just the energy associated with being in
the $n^{{\rm th}}$ energy level:
\begin{equation}
H\psi_{n}=E_{n}\psi_{n}.\label{eq:TISE}
\end{equation}
Eq. \ref{eq:TISE} is just the time-independent version of the Schroedinger
equation, which you have at least heard of. The diagonal elements
are the energies of the $n$ levels and the off-diagonals are associated
with the propensity for tunnelling from level $n$ to level $m$.
Any $2^{N}$ level system can be represented by $N$ spin-$\nicefrac{1}{2}$
particles (\textbf{\uline{qubtis}}), and an example of a spin-$\nicefrac{1}{2}$
particle is simply an electron. Some of the $N$ electrons will have
spin up and some will have spin down, hence $2^{N}$ possibilities.
So instead of $\mathcal{O}(2^{3N})$ operations on a classical computer
for finding the eigenvector with lowest eigenvalue (and hence doing
the completely arbitrary computation), we can just (for example) put
$N$ electrons together %
\begin{comment}
such that the $2^{N}$ energy levels have energies $H_{ii}$ and tunelling
amplitudes $H_{ij}$
\end{comment}
with the appropriate $H$ describing their energy, and then cool the
system down to its ground state. This ground state is one out of $2^{N}$
possible states , and the configuration of spin up and spin down electrons
encodes the desired computation.

\section*{Acknowledgments}

\bibliographystyle{apsrev4-1}
\bibliography{k-local-quadratization}

\end{document}


\documentclass[11pt]{asaproc}
\usepackage[top=1in, bottom=1in, left=1.5in, right=1.5in]{geometry}

\usepackage{microtype}
\usepackage{hyperref}
\usepackage{listings}
\usepackage{natbib}

% Use an APL-friendly font
\usepackage{fontspec}
\setmainfont{Times}
%Download this font from
%http://misc.aplteam.com/apl385.ttf
\setmonofont{APL385}

\lstdefinelanguage{apl}{
  morecomment=[l]{⍝},
  commentstyle={},
  morestring=[b]',
}

\lstdefinelanguage{julia}{
  keywordstyle={\textbf},
  morekeywords={if,else,elseif,while,for,begin,end,quote,try,catch,return,local,abstract,function,generated,macro,ccall,finally,typealias,break,continue,type,global,module,using,import,export,const,let,bitstype,do,in,baremodule,importall,immutable},
  escapeinside={~}{~},
  morecomment=[l]{\#},
  commentstyle={},
  morestring=[b]",
}

\lstset{language=julia, numbers=left, numberstyle=\tiny, mathescape=true,
  basicstyle=\small\ttfamily,
  showspaces=false,
  showstringspaces=false,
}

% https://analyzethedatanotthedrivel.org/2011/08/15/typesetting-utf8-apl-code-with-the-latex-lstlisting-package/
% set lstlisting to accept UTF8 APL text
\makeatletter
\lst@InputCatcodes
\def\lst@DefEC{%
 \lst@CCECUse \lst@ProcessLetter
  ^^80^^81^^82^^83^^84^^85^^86^^87^^88^^89^^8a^^8b^^8c^^8d^^8e^^8f%
  ^^90^^91^^92^^93^^94^^95^^96^^97^^98^^99^^9a^^9b^^9c^^9d^^9e^^9f%
  ^^a0^^a1^^a2^^a3^^a4^^a5^^a6^^a7^^a8^^a9^^aa^^ab^^ac^^ad^^ae^^af%
  ^^b0^^b1^^b2^^b3^^b4^^b5^^b6^^b7^^b8^^b9^^ba^^bb^^bc^^bd^^be^^bf%
  ^^c0^^c1^^c2^^c3^^c4^^c5^^c6^^c7^^c8^^c9^^ca^^cb^^cc^^cd^^ce^^cf%
  ^^d0^^d1^^d2^^d3^^d4^^d5^^d6^^d7^^d8^^d9^^da^^db^^dc^^dd^^de^^df%
  ^^e0^^e1^^e2^^e3^^e4^^e5^^e6^^e7^^e8^^e9^^ea^^eb^^ec^^ed^^ee^^ef%
  ^^f0^^f1^^f2^^f3^^f4^^f5^^f6^^f7^^f8^^f9^^fa^^fb^^fc^^fd^^fe^^ff%
  ^^^^20ac^^^^0153^^^^0152%
  ^^^^20a7^^^^2190^^^^2191^^^^2192^^^^2193^^^^2206^^^^2207^^^^220a%
  ^^^^2218^^^^2228^^^^2229^^^^222a^^^^2235^^^^223c^^^^2260^^^^2261%
  ^^^^2262^^^^2264^^^^2265^^^^2282^^^^2283^^^^2296^^^^22a2^^^^22a3%
  ^^^^22a4^^^^22a5^^^^22c4^^^^2308^^^^230a^^^^2336^^^^2337^^^^2339%
  ^^^^233b^^^^233d^^^^233f^^^^2340^^^^2342^^^^2347^^^^2348^^^^2349%
  ^^^^234b^^^^234e^^^^2350^^^^2352^^^^2355^^^^2357^^^^2359^^^^235d%
  ^^^^235e^^^^235f^^^^2361^^^^2362^^^^2363^^^^2364^^^^2365^^^^2368%
  ^^^^236a^^^^236b^^^^236c^^^^2371^^^^2372^^^^2373^^^^2374^^^^2375%
  ^^^^2377^^^^2378^^^^237a^^^^2395^^^^25af^^^^25ca^^^^25cb%
  ^^00}
\lst@RestoreCatcodes
\makeatother

\bibliographystyle{apalike}

\title{Linguistic Relativity and Programming Languages}

\author{
    Jiahao Chen
    \thanks{Computer Science and Artificial Intelligence Laboratory,
               Massachusetts Institute of Technology,
               Cambridge, Massachusetts, 02139 ({\tt jiahao@mit.edu})}
}

\begin{document}

\maketitle

\begin{abstract}
The use of programming languages can wax and wane across the decades. We
examine the split-apply-combine pattern that is common in statistical
computing, and consider how its invocation or implementation in languages like
MATLAB and APL differ from R/dplyr. The differences in spelling illustrate how
the concept of linguistic relativity applies to programming languages in ways
that are analogous to human languages. Finally, we discuss how Julia, by being
a high performance yet general purpose dynamic language, allows its users to
express different abstractions to suit individual preferences.
\end{abstract}

\begin{keywords}
programming languages, linguistic relativity, APL, MATLAB, R, Julia
\end{keywords}

\section{Each decade has its own programming languages}

Each discipline has its own favorite languages: applied mathematics has MATLAB,
web applications have JavaScript, and high-performance computing still uses
Fortran, accompanied by Python~\citep{scipy} and even Tcl~\citep{Phillips2014}.
Statistical computing, of course, is associated strongly with R. Yet the
boundaries of these seemingly absolute fiefdoms in the kingdom of computing
turn out to be surprisingly malleable on the time scale of decades. Statistical
computing came to prominence with PL/I in the 70s, APL in the 80s, and
XLISP-STAT in the 90s before the relatively modern advent of S and
iR~\citep{deLeeuw2005}. In truth, programming languages come and go beyond the
time scale of single years or even PhD studentships.

So what makes a programming language suitable for the demands of a scientific
discipline like statistical computing?  Discussing pros and cons of different
languages can get bogged down in absolutist statements about what ``can'' and
``cannot'' be done in a language. On some level such statements are absurd,
given that all sufficiently complicated programming languages are Turing
complete, and therefore have the same computational power in the sense of
Turing equivalence. Thus anything that can be done in one Turing-complete
language \textit{must} be doable in another Turing-complete language. Instead,
the answer to the question of suitability must necessarily be ensconced in
``softer'' concepts about ease of use and expressiveness, concepts that are
hard to define precisely but are nonetheless responsible for shaping the
adoption of programming languages.

This paper explores how the suitability of programming languages is related to
expressiveness: what abstractions exist in a given programming language that
map onto ideas that a programmer would want to implement? Closely related is
the notion of idiomaticness: would an experienced programmer in a particular
language recognize and accept a given piece of code as ``idiomatic''?

\subsection{Linguistic relativity and programming languages}

To discuss the suitability of programming languages, I will borrow notions from
the study of \textit{human} languages, linguistics. In particular, I will adopt
the controversial concept of linguistic relativity~\citep{Gumperz1996}, or the
Sapir--Whorf hypothesis~\citep{Brown1976}, and argue that the idea that (human)
languages determine or even constrain cognition has its relevance to computer
languages and programming.

Some of the original writings of Sapir and Whorf seem particularly relevant to
the discussion. Here are some choice quotations:

\begin{quotation}
Human beings do not live in the objective world alone,[...] but are very much
at the mercy of the particular language which has become the medium of
expression for their society [...] [T]he `real world' is to a large extent
unconsciously built up on the language habits of the group.~\citep{Sapir1929}
\end{quotation}

Sapir wrote about human languages, in particular contrasting native American
languages like Hopi against Occidental languages like English. Nevertheless,
programmers would immediately recognize these words about ``language habits''
as echoing a parallel worldview in computer languages, being themselves human
constructs designed to abstract away unwanted, low level machine details.
Some examples of these programming language habits may include:

``Always put data in a data frame''

``Never write for loops; vectorize your code to gain performance.''

Some ``language habits'' can be as banal as choosing between 0- or 1-based
indexing, leading to notoriously unproductive flame wars.  Others are more
subtle. For example, MATLAB treats vectors like column matrices, and therefore
allow operations on one-dimensional objects like \lstinline|v[(2,1)]| indexing
with two numbers, which are disallowed in many other languages like C. We can
trace the different indexing behaviors back to different mathematical starting
points---whereas most languages treat vectors as one-dimensional arrays, i.e.\
``flat'' sequences of numbers, MATLAB by virtue of treating most objects like
matrices, assumes that vectors by default are \textit{column} vectors, and
therefore behave just matrices with one column.

The fact that such discussions of language habits tend to be emotionally
charged is also not a coincidence. Whorf wrote:

\begin{quotation}
[E]very person [...] carries through life certain na\"ive but deeply rooted
ideas about talking and its relation to thinking. Because of their firm
connection with speech habits that have become unconscious and automatic, these
notions tend to be intolerant of opposition.~\citep{Whorf1956sl}
\end{quotation}

Replace ``talking'' with ``writing code'', and the analogy between speech and
computer programs could hardly be plainer. An experienced programmer,
practically by definition, internalizes the boilerplate and design patterns in
code as ``unconscious and automatic'' idioms to be regurgitated on demand
(preferably with an editor or IDE that helps reinforce these idioms
automatically). To the fluent Java programmer, wrapping everything in a class
must be second nature, just as the R user is accustomed to seeing data in a
data frame, or whitespace sensitivity to the Pythonista.  Allowing for code as
a generalization of speech, one could argue that Whorf's observation predicted
the very phenomenon of flame wars over programming language design!

In the rest of this paper, I will make use of another insight from Whorf:

\begin{quotation}
Through [linguistic knowledge], the world as seen from the diverse viewpoints of
other social groups, that we have thought of as alien, becomes intelligible in
new terms. Alienness turns into a new and often clarifying way of looking at
things.~\citep{Whorf1956lmr}
\end{quotation}

I will present a simple, stereotypical data science task and show how solutions
may be implemented in different computer languages, not all of which may
necessarily be familiar to the reader or the typical user of statistical
computing. This side-by-side comparison of the familiar and unfamiliar will
hopefully aid to highlight similarities and differences between the
abstractions expressed within the codes.

\section{A simple data science task: split, apply, combine}

Here is a simple data analysis task that is perhaps emblematic of our house
sharing, carpooling times. Suppose I am a data scientist working at a ride
sharing company and here are the user ratings data for the last ten trips taken
by a particular driver:

\begin{tabular}{r|rrrrrrrrrr}
userid &
381    & 1291   & 3992   & 193942 & 9493   &
381    & 3992   & 381    & 3992   & 193942 \tabularnewline
rating &
5 & 4 & 4 & 4 & 5 & 5 & 5 & 3 & 5 & 4
\end{tabular}

Suppose also that I am interested in working out the average rating given by
each unique user. A seasoned R user might immediately recognize this task
as a ``split-apply-combine'' problem, which could be solved using the
\lstinline|dplyr| package as follows~\citep{Wickham2011}:

\begin{lstlisting}{R}
library(dplyr);
userid = c(381, 1291, 3992, 193942, 9493, 381,
  3992, 381, 3992, 193942)
rating = c(5, 4, 4, 4, 5, 5, 5, 3, 5, 4)
mycar = data.frame(rating, userid)
summarize(group_by(mycar, userid), avgrating=mean(rating))
\end{lstlisting}
\begin{verbatim}
# A tibble: 5 x 2
  userid avgrating
   <dbl>     <dbl>
1    381  4.333333
2   1291  4.000000
3   3992  4.666667
4   9493  5.000000
5 193942  4.000000
\end{verbatim}

The key computation is expressed by the \lstinline|summarize| function, a
higher-order function which combines the data in the \lstinline|mycar| data
frame after being split by (grouped by) \lstinline|userid| and had the function
\lstinline|mean| applied to each group.  This function is provided by
\lstinline|dplyr| and is perfectly well-suited to the split-apply-combine task.
Now let's look at how the same idiom can be expressed in other programming
languages.

\section{MATLAB: split-apply-combine on matrices}

MATLAB is more often thought of as a language for scientific computing rather
than statistical computing. Nevertheless, MATLAB provides a higher order
function, \lstinline|accumarray|, which is perfectly suited to
split-apply-combine computations. Even MATLAB seems to admit that
\lstinline|accumarray| is ``under-appreciated''~\citep{underappreciated};
nevertheless, the function does the job admirably:

\begin{lstlisting}{Matlab}
userids = [381; 1291; 3992; 193942; 9493; 381; 3992; 381; 3992;
  193942];
ratings = [5; 4; 4; 4; 5; 5; 5; 3; 5; 4];
accumarray(userids,ratings,[],@mean,[],true)
\end{lstlisting}
\begin{verbatim}
ans =

                (381,1)                      4.3333
               (1291,1)                      4.0000
               (3992,1)                      4.6667
               (9493,1)                      5.0000
             (193942,1)                      4.0000
\end{verbatim}

Unlike R, which was designed from the beginning around data frames as one of
the fundamental data structures, MATLAB was originally designed with matrices
as the sole data structure~\citep{Moler1980,Moler1982}. While MATLAB as of
R2013b now provides tables as a data structure~\citep{Shure2013}, most of the
base language is still built around matrices and does not work with tables.
\lstinline|accumarray| is one example of the base language that is designed
around matrices.

It can be difficult to determine from the documentation of
\lstinline|accumarray|~\citep{accumarray} that it is a function that solves the
split-apply-combine problem. The first complete sentence in the documentation
states that \lstinline|A=accumarray(val,subs)| ``returns array A by
accumulating elements of vector \lstinline|val| using the subscripts
\lstinline|subs|''. In other words, the most basic use of
\lstinline|accumarray| is to split data in  \lstinline|val| into subsets
grouped by the values of their corresponding entries in \lstinline|val|, with
the summation (accumulation) function applied to each subset. It is clear that
the function is generalizable: a different function can be specified in the
fourth positional argument (MATLAB does not support keyword arguments), but in
order to do so, a default argument must be specified for the third argument.
Finally, the last argument \lstinline|true| specifies that the output should be
returned as a sparse matrix, otherwise the result would be a $193942\times1$
dense matrix with most of the entries zero.

\section{APL: split-apply-combine using array operations}

APL is a language that is built around a single data structure, the
array.\footnote{Some modern implementations such as Dyalog APL~\citep{dyalog15}
have nonstandard extensions that provide support for object-oriented
programming in the form of classes, but we won't consider them here.} APL does
not provide a standard idiom for solving the split-apply-combine problem;
instead, the APL programmer must express split-apply-combine on their own using
lower-level array computations.

One implementation of split-apply-combine might look like this:

\begin{lstlisting}[language=apl]
mean←{+/⍵÷⍴⍵}
uniqfy←{⍵[⍋⍵]}∪
∇a←v splitby k
a←{(⍵⍷k)/v}¨uniqfy k
∇
summarizeby←{(uniqfy ⍵),[1.5]mean¨(⍺ splitby ⍵)}
u←381 1291 3992 193942 9493 381 3992 381 3992 193942
r←5 4 4 4 5 5 5 3 5 4
]display r summarizeby u
\end{lstlisting}
\begin{verbatim}
┌→─────────────────┐
↓   381 4.333333333│
│  1291 4          │
│  3992 4.666666667│
│  9493 5          │
│193942 4          │
└~─────────────────┘
\end{verbatim}

APL functions can take at most two arguments; further arguments must be
specified in ``concealed arguments'', which are variables in global scope.
This solution chose to hard code the function being applied (\lstinline|mean|)
into the higher-level \lstinline|summarizeby| function. Furthermore, dyadic APL
functions must be specified in place, which suggests the name
\lstinline|summarizeby| rather than \lstinline|summarize| as being more natural
to an English speaker. Notably, the expression \lstinline|r summarizeby u|
aligns with the SVO (subject-verb-object) order of English, which can explain
the intuition for why the name \lstinline|summarizeby| may be preferred.

The primary data structure used to implement the ``split'' stage is the nested
array, which allows for the representation of ragged matrices, or list of lists
with unequal lengths. The nested array has long been used to implement
statistical libraries in APL \citep{Anscombe1981,Friendly1994}. In this case,
the nested array is generated by the \lstinline|(⍵⍷k)/v¨|
expression, which extracts each subset of \lstinline|v| by common values
\lstinline|k|. The \lstinline|splitby| function produces the result

\begin{lstlisting}{apl}
]display r splitby u
\end{lstlisting}
\begin{verbatim}
┌→──────────────────────────────┐
│ ┌→────┐ ┌→┐ ┌→────┐ ┌→┐ ┌→──┐ │
│ │5 5 3│ │4│ │4 5 5│ │5│ │4 4│ │
│ └~────┘ └~┘ └~────┘ └~┘ └~──┘ │
└∊──────────────────────────────┘
\end{verbatim}

corresponding to the keys

\begin{lstlisting}{apl}
]display uniqfy u
\end{lstlisting}
\begin{verbatim}
┌→────────────────────────┐
│381 1291 3992 9493 193942│
└~────────────────────────┘
\end{verbatim}

The ``apply'' stage of the computation uses APL's built-in diaeresis
(\lstinline|¨|, ``over each'') function. Finally, the ``combine'' stage
produces a two-column matrix, with the first column containing the unique keys
and the second column containing the required means. This matrix is produced by
the \lstinline|,[1.5]| expression, which ``laminates'' its two arguments
together.

Notably, the APL solution might be considered by some expert programmers to be
not idiomatic. Instead, there is a long tradition of writing concise one-line
APL solutions to various problems, and for this problem, such a solution might
look like

\begin{lstlisting}{apl}
{⍵,[1.5]{mean¨{(⍵⍷u)/r}¨⍵}¨⍵}{⍵[⍋⍵]}∪u
\end{lstlisting}

To summarize, the three solutions we have seen so far each have different code
organizations and work on different data structures. In tabular form:

\begin{tabular}{c|ccc}
 & R/dplyr & MATLAB & APL\tabularnewline
\hline
split & summarize & accumarray & splitby\tabularnewline
apply & (column constructor) & (positional argument) & ¨\tabularnewline
combine & summarize & accumarray & summarizeby\tabularnewline
data structure & data frame (tibble) & matrix & array\tabularnewline
\end{tabular}

\section{Julia: flexibility of idioms}

The last language I will consider here is Julia, a general-purpose programming
language that was originally designed for technical
computing~\citep{Bezanson2015}\footnote{All the Julia code presented here is
written for version 0.5.0.}. Julia is a language that is easy for both
compilers and programmers to understand, in the sense that it is a high level
dynamic language with language constructs that facilitate compiler analysis and
generation of efficient code.

The result of Julia's careful design for expressiveness and performance allows
for the different solutions above for the split-apply-combine problem to all be
expressible in the same language.
The solution to split-apply-combine in R/dplyr derives its performance from an
underlying implementation of dplyr in C++ (via Rcpp). In contrast, all the
Julia solutions in this section are written in pure Julia. The result is that
Julia users can also be Julia developers without necessarily having to learn
another language to work on the underlying implementation which does all the
heavy lifting. Another advantage is that Julia users can experiment with
different idioms and data structures without being confined to just those that
have well-optimized implementations, and enjoy reasonable performance in many
cases.

For example, the \lstinline|DataFrames.jl| package provides two different
spellings for the R/dplyr approach:

\begin{lstlisting}{julia}
using DataFrames
df = DataFrame(
  userids=[381, 1291, 3992, 193942, 9494, 381, 3992, 381, 3992,
  193942], ratings=[5, 4, 4, 4, 5, 5, 5, 3, 5, 4]);
by(df, :userids, df->mean(df[:ratings])) #Same as next line
aggregate(df, :userids, mean)
\end{lstlisting}
\begin{verbatim}
5×2 DataFrames.DataFrame
│ Row │ userids │ ratings_mean │
├─────┼─────────┼──────────────┤
│ 1   │ 381     │ 4.33333      │
│ 2   │ 1291    │ 4.0          │
│ 3   │ 3992    │ 4.66667      │
│ 4   │ 9494    │ 5.0          │
│ 5   │ 193942  │ 4.0          │
\end{verbatim}

The solution to split-apply-combine in R/dplyr derives its performance from an
underlying implementation of dplyr in C++ (via Rcpp). In contrast, the Julia
solutions are written in pure Julia. The result is that Julia users can also be
Julia developers without necessarily having to learn another language to work
on the underlying implementation which does all the heavy lifting. Another
advantage is that Julia users can experiment with different idioms and data
structures without being confined to just those that have well-optimized
implementations, and enjoy reasonable performance in many cases.

For example, a user who is unfamiliar with data frames and may prefer instead
an array-based solution may choose to implement an APL-style solution using a
simple list comprehension:

\begin{lstlisting}{julia}
userids=[381, 1291, 3992, 193942, 9494, 381, 3992, 381, 3992,
  193942]
ratings=[5, 4, 4, 4, 5, 5, 5, 3, 5, 4]
[(u, mean(ratings[userids.==u])) for u in unique(userids)]
\end{lstlisting}
\begin{verbatim}
5-element Array{Tuple{Any,Any},1}:
 (381,4.333333333333333)
 (1291,4.0)
 (3992,4.666666666666667)
 (193942,4.0)
 (9494,5.0)
\end{verbatim}

The list comprehension approach is simple and concise, if not particularly
fast. Nevertheless, the ability to rewrite a solution multiple different way in
Julia allows for Julia users to experiment with different approaches in order
to find one with the most acceptable performance. For example, a Julia user may
choose to rewrite the list comprehension solution by writing out for loops
explicitly, something that is discouraged in all the other languages discussed
here (which promote the ``vectorize your code'' habit). One such implementation
example might look like the following:

\begin{lstlisting}{julia}
counts = []
uuserids=[]
uratings=[]
for i in eachindex(userids)
    j = findfirst(uuserids, userids[i])
    if j==0 #not found
        push!(uuserids, userids[i])
        push!(uratings, ratings[i])
        push!(counts, 1)
    else #already seen
        uratings[j] += ratings[i]
        counts[j] += 1
    end
end
[uuserids uratings./counts]
\end{lstlisting}
\begin{verbatim}
5x2 Array{Any,2}:
    381  4.33333
   1291  4.0
   3992  4.66667
 193942  4.0
   9494  5.0
\end{verbatim}

Finally, a Julia user may later recognize this code as implementing the
split-apply-combine idiom and choose to refactor this code into a reusable
function akin to \lstinline|accumarray|. In fact, \lstinline|accumarray| itself
can be implemented in Julia with just a few lines of code:

\begin{lstlisting}{julia}
function accumarray{Tk,Tv}(
        subs::AbstractArray{Tk}, val::AbstractArray{Tv},
        func=sum, fillval=zero(Tv)
      ; sz=maximum(subs,1), issparse=false)

   counts = Dict{Vector{Tk},Vector{Tv}}()
   for i = 1:size(subs, 1)
       counts[subs[i, :]] = #split
           Tv[get(counts,subs[i, :], Tv[]); val[i...]]
   end

   A = issparse ? spzeros(sz...) : fill(fillval, sz...) #combine
   for (key, val) in counts
        A[key...]= func(val) #apply
   end
   return A
end
\end{lstlisting}

Thus even though \lstinline|accumarray| does not exist in the base Julia
library, an experienced user can, without much difficulty, refactor a previous
solution into a part that implements the general purpose \lstinline|accumarray|
function. Having multiple options gives Julia users the possibility of choosing
the best trade-off between development time and actual execution time when
deployed on large data sets.

\section{Conclusion}

Many programming languages dictate one preferred way of doing things, which
often encompasses an unwritten set of ``language habits'' as well as a choice
of preferred data structures. In particular, ``vectorize your code'' is an
idiom that is common to R, MATLAB and APL, three languages that are currently
or in the past been popular for statistical computing. One reason high level
languages have a preferred way of expression is because those idioms over a few
preferred data structures have highly optimized implementations and are well
integrated into a comprehensive standard library. As a result, these idioms
shape the way experienced programmers think about solving problems in those
languages.

The promise of Julia, as a high level dynamic language with reasonable
performance, allows for multiple approaches to the same problem. An experienced
user can, without much difficulty, iterate rapidly from a na\"ive slow solution
to a fast, specialized solution, and further to a fast, general purpose
solution.

\section*{Acknowledgments}

I would like to thank the Julia developer community for many useful
discussions, in particular Alan Edelman for the discussion of how
\lstinline|accumarray| may be implemented in Julia.

\bibliography{bib/bib}

\end{document}


\documentclass{article}

%%%%%% Include Packages %%%%%%
\usepackage{sectsty}
\usepackage{amsmath,amsfonts,amsthm,amssymb}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{setspace}
\usepackage{graphicx}
\usepackage{array}

%%%%%% Formatting Modifications %%%%%%

\usepackage[margin=2.5cm]{geometry} %% Set margins
\sectionfont{\sectionrule{0pt}{0pt}{-8pt}{0.8pt}} %% Underscore section headers
\setstretch{1.2} %% Set 1.2 spacing

%%%%%% Set Homework Variables %%%%%%

\newcommand{\hwkNum}{7}
\newcommand{\hwkAuthors}{Ben Drucker}

%%%%%% Set Header/Footer %%%%%%

\pagestyle{fancy}
\lhead{\hwkAuthors}
\rhead{Homework \#\hwkNum}
\rfoot{\textit{\footnotesize{\thepage /\pageref{LastPage}}}}
\cfoot{}
\renewcommand\headrulewidth{0.4pt}
\renewcommand\footrulewidth{0.4pt}

%%%%%% Document %%%%%%

\begin{document}

\title{Homework \#\hwkNum}
\author{\hwkAuthors}
\date{}

\maketitle

%%%%%% Begin Content %%%%%%

\section*{5.3}
	\subsection*{38}
		\subsubsection*{a)} The first row ($P_{t_0}$) represents the PMF of $T_0$: \\ \\
			\begin{tabular}{c || c | c | c | c | c | c}
				\hline
				$t_0$ & 0 & 1 & 2 & 3 & 4 & $\sum$\\ \hline \hline
				$P(t_0)$ & .04 & .2 & .37 & .3  & .09 & 1 \\ \hline
				$t_0P(t_0)$ & 0 & .2 & .74 & .9 & .36 & 2.2\\ \hline
				$t_0^2P(t_0)$ & 0 & .2 & 1.48 & 2.7 & 1.44 & 5.82\\
				\hline
			\end{tabular}
		\subsubsection*{b)}
			$\mu_{T_0} = \sum t_0 P(t_0) = 2.2;~~ \mu_{T_0} = 2\mu $
		\subsubsection*{c)}
			$\sigma^2_{T_0} = \sum t_0^2 P(t_0) - \mu_{T_0}^2 = 5.82 - 2.2^2 = .98;~~ \sigma^2_{T_0} = 2\sigma^2$
		\subsubsection*{d)}
			$E(T_0) = 4.4;~~ V{T_0} = 1.96$
		\subsubsection*{e)}
			$P(T_0 = 8) = .09^2 = .0081; ~~ P(T_0 \geq 7) = P(T_0 = 8) + 2*.3*.09 = .0081 + .054 = .0621$
	\subsection*{42)}
		\subsubsection*{a)}
			\begin{tabular}{c || c | c | c | c | c | c | c}
				$\overline{x}$ & 27.75 & 28 & 29.7 & 29.95 & 31.65 & 21.9 & 33.6 \\ \hline
				$p(\overline{x})$ & $\frac{4}{30}$ & $\frac{2}{30}$ & $\frac{6}{30}$ & $\frac{4}{30}$ & $\frac{8}{30}$ & $\frac{4}{30}$ & $\frac{2}{30}$
			\end{tabular}
		\subsubsection*{b)}
			\begin{tabular}{c || c | c | c}
				$\overline{x}$ & 27.75 & 31.65 & 31.9 \\ \hline
				$p(\overline{x})$ & $\frac{1}{3}$ & $\frac{1}{3}$ & $\frac{1}{3}$
			\end{tabular}
		\subsubsection*{c)}
			$E(X)_a = E(X)_b = \mu = 30.4\overline{3}$
\section*{5.4)}
	\subsection*{46}
		\subsubsection*{a)}			 			$E(\overline{X}) = \mu = 12 \\ \sigma_{\overline{x}} = \frac{\sigma_x}{\sqrt{n}} = \frac{.04}{4} = .01$

		\subsubsection*{b)}
			$ E(\overline{X}) = \mu =12\\
			\sigma_{\overline{x}} = \frac{\sigma_x}{\sqrt{n}} = \frac{.04}{8} = .005 $
		\subsubsection*{c)}
			The second sample, which has less variability due to the larger $n$.
	\subsection*{48}
		\subsubsection*{a)}
			Yes. Given that the population is men 18 years of age, it is plausible to assume a symmetric distribution around an unknown mean with decreasing frequency with increasing distance from the mean. If the population were all 18 year olds, the population would likely be bi-model because of sex differences.
		\subsubsection*{b)}
			$\mu = 85; ~~ \sigma_{\overline{x}} = \frac{15}{\sqrt{277}} \approxeq .901262\\
			P(\overline{X} \geq 86.3) = 1- P(\overline{X} \leq 86.3) = 1- P \left(Z < \Phi \left [ \frac{86.3 - 85}{.901262} \right ] \right) = 1- P(Z < 1.442) = 1- .425 = .575
			$
		\subsubsection*{c)}
			$\mu = 82; ~~ \sigma_{\overline{x}} = .901262\\
			P(\overline{X} \geq 86.3) = 1- P(\overline{X} \leq 86.3) = 1- P \left(Z < \Phi \left [ \frac{86.3 - 82}{.901262} \right ] \right) = 1- P(Z < 4.77) \approx 0
			$. \\ 82 cm would not be reasonable.
	\subsection*{56)}
		\subsubsection*{a)}
			$ \mu = np = 1000 *.1 = 100; ~~ \sigma = \sqrt{\mu(1-p)} = \sqrt{100*.9} = 9.486832981.$
			\begin{align*}
				P(X \leq 125) &= P \left ( \frac{X - \mu}{\sigma} \leq \frac{125 - \mu}{\sigma} \right ) \\
				&= P \left ( Z \leq \frac{125-100}{9.486832981} \right ) \\
				&= P(Z < 2.64) \\
				&= .996
			\end{align*}
		\subsubsection*{b)}
			Let $\Delta$ be the difference in errors between the two independent transmissions:
			\begin{align*}
				P(|\Delta| \leq 50 &= P(-50 \leq \Delta \leq 50) \\
				&= P \left ( \frac{-50}{\sigma} \leq Z \leq \frac{50}{\sigma} \right ) \\
				& \approx P \left ( \frac{50}{\sqrt{2np(1-p)}} = \frac{-50}{\sqrt{2*1000*.1*(1-.1)}} = -3.7268 \leq Z \leq 3.7268 \right ) \\
				&= .999903 - .00009697 = .99980603
			\end{align*}
\section{5.5}
	\subsection*{60}
		$\mu_Y = \frac{1}{2}(\mu_1 + \mu_2) - \frac{1}{3}(\mu_3 + \mu_4 + \mu_5)= -1 \\
		\sigma_Y^2 = \frac{1}{4} \sigma_1^2 + \frac{1}{4} \sigma_2^2 + \frac{1}{9} \sigma_3^2 + \frac{1}{9} \sigma_4^2 + \frac{1}{9} \sigma_5^2 = 3.167;~ \sigma_Y = \sqrt{3.167} = 1.7795\\
		P(Y \geq 0) = P \left ( Z \geq \frac{1}{1.7795} \right ) = P(Z \geq .56) = 1-P(Z \leq .56) = .2877 \\
		P(-1 \leq Y \leq 1) = P \left (0 \leq Z \leq \frac{2}{1.7795} \right ) = P(Z < 1.12) = .369$
	\subsection*{64)}
		$X_1..X_5$ for morning, $X_6..X_{10}$ for evening.
		\subsubsection*{a)}
			$E(X_1+...+X_10) = 5E(X_1) + 5(X_6) = 5*4+5*5 = 45$
		\subsubsection*{b)}
			$\sigma^2 = 5Var(X_1) + 5(X_6) = 5 \left ( \frac{8^2}{12} + \frac{10^2}{12} \right ) = \frac{820}{12} = 68.\overline{3}$
		\subsubsection*{c)}
			$E(X_1 - X_6) = E(X_1) - E(X_6) = 4-5 = -1 \\
			Var(X_1-X_6) = Var(X_1) + Var(X_6) = \frac{64}{12} + \frac{100}{12} = 13.\overline{6}$
		\subsubsection*{d)}
			$E[(X_1+ ...+ X_5) - (X_6 + ... + X_{10})] = 5*4 - 5*5 = -5 \\
			Var[(X_1+ ...+ X_5) - (X_6 + ... + X_{10})] =Var(X_1+ ...+ X_5) + Var(X_6 + ... + X_{10}) = 68.\overline{3}$
	\subsection*{70}
		\subsubsection*{a)}
			$$ E(Y_i) = \frac{1}{2} \rightarrow E(W) = \sum_{i=1}^n iE(Y_i) = \frac{1}{2} \sum_{i=1}^ni = \frac{n^2 + n}{2^2}	$$
		\subsubsection*{b)}
			$$ Var(Y_i) = \frac{1}{4} \rightarrow Var(W) = \sum_{i=1}^n i^2 Var(Y_i) = \frac{1}{4} \sum_{i=1}^n i^2 = \frac{(n^2+n)(2n+1)}{4 * 2^2}$$

%%%%%% End Content %%%%%%
\end{document}

Spring 2013/STAT W1211 - Statistics/Homework/Homework 7/Homework 7.tex


\documentclass{beamer}
\usepackage{hyperref}
\usepackage{subfig}  %% Para incluir subgraficos
\usepackage{media9} %
\usepackage{url}

\hypersetup{pdfstartview={Fit}, bookmarks=True, pdftitle={Wave Propagation Lectures},
            pdfauthor={Nicolas Guarin-Zapata}, pdfsubject={Lectures},
            pdfkeywords={Waves, Elasticity, Numerical Methods}}  % Configure hyperref

%--- New commands ----%
\newcommand{\footref}[1]{\textsuperscript{\ref{#1}}}
\newcommand{\pardiff}[2]{\frac{\partial #1}{\partial #2}}
\newcommand{\pardiffd}[2]{\frac{\partial^2 #1}{\partial #2^2}}
%---------------------%

%\usefonttheme[onlymath]{serif}  % Make equations to be in serif fonts
\usefonttheme{serif}  % Make equations to be in serif fonts

\begin{document}

%title
\title[Wave propagation in solids] % (optional, only for long titles)
{Wave propagation:}
\subtitle{Solid Mechanics}
\author[Guarin-Zapata, Nicolas] % (optional, for multiple authors)
{Nicol\'as Guar\'in Zapata\\ \texttt{\small nguarin@purdue.edu}\\
{\tiny Slides available at: \url{https://github.com/nicoguaro/CE597-slides}}}
\institute{Civil Engineering Department\\
  Purdue University}
\date{\today}
\subject{Wave propagation}

% Title page
\frame{\titlepage}

% Outline
\begin{frame}
	\frametitle{Outline}
	\tableofcontents
\end{frame}
%

% Introduction about waves in general
\section{Introduction}
\begin{frame}
\frametitle{Introduction}
A wave is the propagation of certain medium property perturbation, e.g., density, pressure, electric field or magnetic field, that travel through the space transporting energy. The perturbed medium could be of diverse nature like air, water, a piece of metal or vacuum.

The property that presents the phenomena is expressed as function of position and time $\psi(\vec{r},t)$. Mathematically  it is said that $\psi$ is a wave if it verifies the wave equation:
\[\nabla^2 \psi(\vec{r},t)= \frac{1}{v^2} \frac{\partial^2 }{\partial t^2}\psi(\vec{r},t) \enspace ,\]
where $v$ is the wave propagation speed. For instance, some perturbations of the pressure, called sound, verify the above equation.
\end{frame}

% Examples
\subsection{Examples}
\begin{frame}\frametitle{Global Seismic Wave Propagation Simulation}
\begin{figure}[H]
\centering
\includemedia[
  width=0.5\textwidth,
  height=0.5\linewidth,
  activate=pageopen,
  addresource=vids/global.flv,
  flashvars={source=vids/global.flv}
]{}{VPlayer.swf}
\caption{Global Seismic Wave Propagation Simulation.\footnote{Contributors from ICES, The University of Texas at Austin: Carsten Burstedde, Omar Ghattas, James R. Martin, Georg Stadler, Lucas C. Wilcox Visualization at the Texas Advanced Computing Center, the University of Texas at Austin by Greg Abram: \url{http://vimeo.com/30813579}}}
\label{vid:global}
\end{figure}
\end{frame}

\begin{frame}\frametitle{Global Seismic Wave Propagation Simulation}
\begin{figure}[H]
\centering
\includemedia[
  width=0.8\textwidth,
  height=0.45\linewidth,
  activate=pageopen,
  addresource=vids/asymmetric_cannon.flv,
  flashvars={source=vids/asymmetric_cannon.flv}
]{}{VPlayer.swf}
\caption{Vertical Plane SH wave in an asymmetric canyon.\footnote{Juan Diego Jaramillo et al. 2012}}
\label{vid:canyon}
\end{figure}
\end{frame}

\begin{frame}\frametitle{Scattering of a pressure wave around a long cylinder}
\begin{figure}[H]
\centering
\includemedia[
  width=0.8\textwidth,
  height=0.6\linewidth,
  activate=pageopen,
  addresource=vids/scat-cylinder.flv,
  flashvars={source=vids/scat-cylinder.flv}
]{}{VPlayer.swf}
\caption{Scattering of a pressure wave around a long cylinder }
\label{vid:cylinder}
\end{figure}
\end{frame}

% Wave characteristics
\section{Wave characteristics}
\begin{frame}
	\frametitle{Wave characteristics}
There are great variety of waves but all of them could experiment
\begin{itemize}
\item \textbf{Reflection}:Occurs when a wave find a new medium, that can not cross, change its direction.

\item \textbf{Refraction}: Occurs when a wave change its direction when enter in a new medium with different propagation speed.

\item \textbf{Doppler Effect}: Effect caused by the relative motion between the source and the receptor.

\item \textbf{Interference}: Occurs when two or more waves coexist in the same place and are superimposed.

\item \textbf{Diffraction}: Occurs when a wave find the border of an obstacle and change its \emph{form} to round it.
\end{itemize}

\end{frame}

% Waves in a string
\section{Waves in a string}
\subsection{Formulation}
\begin{frame}\frametitle{Waves in a string}

\transwipe

\begin{figure}[h]
	\centering
	\includegraphics[height=4cm]{img/string.pdf}
	\caption{Forces diagram over an element of the string with length $\Delta x$. }
\end{figure}

\only<1> {For a string with length $L$, linear mass density $\mu$ and a tension $T$, let's take a small segment with small displacements in $y$. The force balance over the element showed in the Figure is:
\begin{align*}
F_y &= T \sin(\theta + \Delta \theta) - T \sin(\theta)\\
F_x &= T \cos(\theta + \Delta \theta) - T \cos(\theta) \enspace ,
\end{align*}}

\only<2>{Taking small displacements in the string, the angles are also small and then
\begin{align*}
F_y &\approx T (\theta + \Delta \theta) - T (\theta) = T \Delta \theta\\
F_x &\approx 0 \enspace .
\end{align*}}
\end{frame}

\begin{frame}[allowframebreaks]\frametitle{Waves in a string}
From the second Newton's law we get
\[T\ \Delta \theta = \underbrace{(\mu\ \Delta x)}_\text{mass} a_y \enspace ,\]
if we take the limit $\Delta x \rightarrow dx$
\begin{equation}
T\ d\theta = (\mu\ dx) a_y \enspace .
\label{eq:stringForce}
\end{equation}
And we know that $\tan \theta = \frac{\partial y}{\partial x}$, taking derivative respect $x$
\[\sec^2 \theta \frac{d\theta}{dx} = \frac{\partial^2 y}{\partial x^2} \enspace .\]
Due to small displacements $\sec^2 \theta \approx 1$, hence
\begin{equation}
d\theta \approx \frac{\partial^2 y}{\partial x^2} dx
\label{eq:stringDtheta}
\end{equation}
and replacing (\ref{eq:stringDtheta}) in  (\ref{eq:stringForce})
\[T \frac{\partial^2 y}{\partial x^2} dx = (\mu\ dx) \frac{\partial^2 y}{\partial t^2} \enspace ,\]
we finally get the 1D Wave Equation
\[\frac{\partial^2 y}{\partial x^2} = \frac{\mu}{T} \frac{\partial^2 y}{\partial t^2} \enspace .\]

$T/\mu$ have square speed units, and is the square propagation speed
\[v = \sqrt{\frac{T}{\mu}} \enspace ,\]
so
\begin{equation}
\frac{\partial^2 y}{\partial x^2} = \frac{1}{v^2} \frac{\partial^2 y}{\partial t^2} \enspace .
\label{eq:wave_eq}
\end{equation}

\end{frame}

% Solution for the 1D Case
\subsection{Solution}
\begin{frame}[allowframebreaks]\frametitle{Solution for the 1D case}

The wave equation could be solved by separation of variables, i.e., let's suppose it has a solution of the form $y=y(x,t)=X(x)T(t)=X\ T$
\[\frac{1}{X} \frac{d^2 X}{dx^2} - \frac{1}{v^2 T} \frac{d^2 T}{dt^2} = 0 \enspace ;\]
we can see that the temporal and the spatial terms are isolated, so they should be equal to a constant. For simplicity let's take $-\alpha^2$, with $\alpha\in \mathbb{R}$
\[\frac{d^2 X}{dx^2}=-\alpha^2 X, \qquad \frac{d^2 T}{dt^2}=-\alpha^2 v^2 T \enspace ,\]
so the solution is
\[y = \left[C_1 \sin(\alpha x)+ C_2\cos(\alpha x) \right] \left[C_3\sin(\alpha v t) +C_4 \cos(\alpha v t)\right] \enspace .\]
If we take fixed extremes and assume that the string starts with a deformed shape $f(x)$, i.e., $y(0,t)=y(L,t)$, $y(x,0)=f(x)$ and $y'(x,0)=0$ can be shown that the complete solution is
\[y(x,t) = \frac{2}{L}\sum\limits_{n=1}^{\infty}\left[\int\limits_{0}^{L}f(\xi)\sin\left(\frac{n\pi\xi}{L}\right)d\xi\right] \sin\left(\frac{n\pi x}{L}\right)\cos\left(\frac{n\pi v t}{L}\right) \enspace .\]
\end{frame}

\subsection{An example}
\begin{frame}\frametitle{Example in 1D}
% Encoding for media9: ffmpeg -i movie.avi -sameq movie.flv  or
%                      ffmpeg -i movie.avi -sameq -vcodec libx264 -x264opts keyint=25 movie.mp4
\begin{figure}[H]
\centering
\includemedia[
  width=0.8\textwidth,
  height=0.6\linewidth,
  activate=pageopen,
  addresource=vids/ex1D.flv,
  flashvars={source=vids/ex1D.flv}
]{}{VPlayer.swf}
\caption{Wave traveling in a string.}
\label{vid:string}
\end{figure}
\end{frame}

% Speed Wavelength and Frequency
\begin{frame}\frametitle{Wavelength}
Once the speed of propagation is known, the frequency of the sound produced by the string can be calculated. The speed of propagation of a wave is equal to the wavelength $\lambda$ divided by the period $\tau$, or multiplied by the frequency $f$:
\[v \equiv \sqrt{\frac{T}{\mu}} =\frac{\lambda}{\tau} = \lambda f \enspace .  \]
\begin{figure}[h]
	\centering
	\includegraphics[height=3cm]{img/Sine_wavelength.pdf}
	\caption{Wavelength of a sine wave, $\lambda$, can be measured between any two points with the same phase, such as between crests, or troughs, or corresponding zero crossings as shown.}
\end{figure}
\end{frame}

%% Elastic waves
\section{Elastic waves}
\subsection{Starting point}
\begin{frame}\frametitle{Navier-Cauchy Equations: Starting Point}
In a three dimensional solid we can describe waves starting from the continuity equation, motion equations and constitutive relationships.
\begin{itemize}
\item Continuity:
\[\frac{\partial}{\partial t}\rho = - \frac{\partial}{\partial x_i}\left( \rho \frac{\partial}{\partial t} u_i\right)\]

\item Equations of Motion:
\[ \frac{\partial^2}{\partial t^2}(\rho u_i) = \frac{\partial}{\partial x_j} \sigma_{ij} + f_i \]

\item Constitutive relationships:
\[\sigma_{ij} = C_{ijkl} \epsilon_{kl}  \enspace ,\]

\end{itemize}
where $u_i$ is the displacement of a material point in $i$ direction, $\rho$ is the mass density, $\sigma_{ij}$ the stress tensor, $\epsilon_{kl}$ is the strain tensor, $f_i$ are \emph{body forces} and $C_{ijkl}$ depends on the material of the medium.
\end{frame}

% continuity equation
\subsubsection{Continuity equation}
\begin{frame}[allowframebreaks]\frametitle{Continuity equation}
\begin{figure}[h]
	\centering
	\includegraphics[height=6cm]{img/continuity.pdf}
	\caption{Fluxes on a parallelepiped element.}
\end{figure}
The total mass of the element is $M_T = \rho dx\, dy\, dz$, and its rate is
\[\pardiff{M_T}{t} = \pardiff{\rho}{t} dx\, dy\, dz \enspace .\]
We can compute the total flow through the $x$ direction:
\[\left[ \rho \pardiff{u_1}{t} + \pardiff{}{x}\left(\rho \pardiff{u_1}{t}\right) dx\right] dy\, dz - \rho \pardiff{u_1}{t} dy\, dz = \pardiff{}{x}\left(\rho \pardiff{u_1}{t}\right)dx\, dy\, dz \enspace .\]
Similarly, for the other directions
\[\pardiff{}{y}\left(\rho \pardiff{u_2}{t}\right)dx\, dy\, dz,\qquad \pardiff{}{z}\left(\rho \pardiff{u_3}{t}\right)dx\, dy\, dz \enspace ,\]
and equating to the first expression
\[\pardiff{\rho}{t} + \pardiff{}{x}\left(\rho \pardiff{u_1}{t}\right) + \pardiff{}{y}\left(\rho \pardiff{u_2}{t}\right) + \pardiff{}{z}\left(\rho \pardiff{u_3}{t}\right) = 0\enspace .\]
In index notation
\[\pardiff{\rho}{t} = - \pardiff{}{x_i}\left(\rho \pardiff{u_i}{t}\right) \quad \text{Summation over } i \enspace ,\]
and, in vector notation
\[\pardiff{\rho}{t} = - \nabla \cdot \left(\rho \pardiff{\vec{u}}{t}\right) \enspace.\]
\end{frame}

% Balance of momentum
\subsubsection{Balance of momentum}
\begin{frame}[allowframebreaks]\frametitle{Balance of momentum: ``Equations of Motion"}
\begin{figure}[h]
	\centering
	\includegraphics[height=6cm]{img/momentum.pdf}
	\caption{Stresses on a parallelepiped element.}
\end{figure}
We are going to do the balance of forces in the $x_1$ direction
\begin{align*}
\rho \pardiffd{u_1}{t} dx\, dy\, dz =& \left(\sigma_{11} + \pardiff{\sigma_{11}}{x_1}dx_1\right)dx_2\, dx_3 - \sigma_{11} dx_2\, dx_3\\
&+ \left(\sigma_{21} + \pardiff{\sigma_{21}}{x_2}dx_2\right)dx_1\, dx_3
 -\sigma_{21}dx_1\, dx_3\\
&+ \left(\sigma_{31} + \pardiff{\sigma_{31}}{x_3}dx_3\right)dx_1\, dx_2\\
&- \sigma_{31}dx_1\, dx_2 + f_1 dx_1\, dx_2\, dx_3 \\
=& \left(\pardiff{\sigma_{11}}{x_1} + \pardiff{\sigma_{21}}{x_2} + \pardiff{\sigma_{31}}{x_3}\right)dx_1\, dx_2\, dx_3
\end{align*}
upon dividing by $dx_1\, dx_2\, dx_3$ we obtain
\[\pardiff{\sigma_{11}}{x_1} + \pardiff{\sigma_{21}}{x_2} + \pardiff{\sigma_{31}}{x_3} + f_1= \rho \pardiffd{u_1}{t} \enspace ,\]
similarly in the other two directions
\begin{align*}
\pardiff{\sigma_{12}}{x_1} + \pardiff{\sigma_{22}}{x_2} + \pardiff{\sigma_{32}}{x_3} =& \rho \pardiffd{u_3}{t} \\
\pardiff{\sigma_{13}}{x_1} + \pardiff{\sigma_{23}}{x_2} + \pardiff{\sigma_{33}}{x_3} =& \rho \pardiffd{u_3}{t} \enspace .
\end{align*}
In index notation
\[\pardiff{\sigma_{ji}}{x_j} + f_i = \rho\pardiffd{u_i}{t}\qquad \text{Summation over } j \enspace ,\]
and in vector notation
\[\nabla\cdot \sigma + \vec{f} = \rho \pardiffd{\vec{u}}{t} \enspace .\]
\end{frame}

\begin{frame}[allowframebreaks]\frametitle{Navier-Cauchy Equations: Deduction}
For an isotropic medium the constitutive relation can be expressed as
\[\sigma_{ij} = \lambda \delta_{ij}\epsilon_{kk} + 2\mu \epsilon_{ij} \enspace ,\]
being $\lambda$ and $\mu$ the Lame parameters.

$\epsilon_{ij}$ is usually define as
\[\epsilon_{ij} = \frac{1}{2} \left( \pardiff{u_i}{x_j} + \pardiff{u_j}{x_i} \right) \enspace ,\]
so
\[\sigma_{ij} = \lambda \delta_{ij} \pardiff{u_k}{x_k} + \mu \left( \pardiff{u_i}{x_j} + \pardiff{u_j}{x_i} \right) \enspace .\]

If we take the constitutive equation and replace $\sigma_{ij}$ in the motion equation (assuming that $\pardiff{\rho}{t}=0$).
\[\rho \pardiff{u_i}{t} = \delta_{ij} \lambda \pardiff{\epsilon_{kk}}{x_j} + 2\mu \pardiff{\epsilon_{ij}}{x_j} +f_i \enspace ,\]
and rewriting the right hand side in terms of the displacements we have
\[\rho \pardiff{^2 u_i}{t^2} = \delta_{ij} \lambda \pardiff{}{x_j}\left( \pardiff{u_k}{x_k}\right) + \mu \pardiff{ }{x_j}\left( \pardiff{u_i}{x_j} + \pardiff{u_j}{x_i}\right) + f_i \enspace ,\]
operating the Kronecker's delta
\[\rho \pardiff{^2 u_i}{t^2} = \lambda \pardiff{}{x_i}\left( \pardiff{u_k}{x_k}\right) + \mu \pardiff{}{x_j}\left( \pardiff{u_i}{x_j} + \pardiff{u_j}{x_i} \right) + f_i \enspace ,\]
and this can be rewritten like
\[\rho \pardiff{^2 u_i}{t^2} = \lambda  \pardiff{^2 u_j}{x_i x_j} + \mu \pardiff{^2 u_i}{x_j^2} + \mu \pardiff{^2 u_j}{x_j x_i} + f_i \enspace ,\]
grouping terms
\begin{equation}
\rho \pardiff{^2 u_i}{t^2} = (\lambda + \mu)  \pardiff{}{x_i}\left( \pardiff{u_j}{x_j} \right) + \mu \pardiff{^2 u_i}{x_j^2}  + f_i \enspace .
\label{eq:navierInd}
\end{equation}
This is the Navier Equation that can be expressed also in vector form
\[\rho \pardiff{^2 u_i}{t^2} = (\lambda + \mu)  \underbrace{\pardiff{}{x_i}}_{\mbox{grad}}\nabla \cdot \vec{u} + \mu \nabla^2 u_i + f_i \enspace ,\]
or
\begin{equation}
\rho \pardiff{^2 \vec{u}}{t^2} = (\lambda + \mu)  \nabla (\nabla\cdot \vec{u})+ \mu \nabla^2 \vec{u} + \vec{f} \enspace .
\label{eq:navierVec}
\end{equation}
The body forces will be neglected hereinafter for simplicity. The vector
\[\nabla^2 \vec{a} = \nabla (\nabla \cdot \vec{a}) - \nabla \times (\nabla \times \vec{a}) \enspace ,\]
identity is used, and we get
\[\rho \pardiff{^2 \vec{u}}{t^2} = (\lambda + 2\mu) \nabla(\nabla \cdot \vec{u}) - \mu (\nabla \times (\nabla \times \vec{u})) \enspace .\]
If we take $\varphi = \nabla \cdot \vec{u} $ and $\vec{\psi} = \nabla \times \vec{u}$ and replace it in the Navier equation we obtain:
\begin{equation}
\rho \pardiff{^2 \vec{u}}{t^2} = (\lambda + 2\mu) \nabla \varphi - \mu \nabla \times \vec{\psi} \enspace .
\label{eq:waveHelm}
\end{equation}
\end{frame}

% P-waves
\subsection{P-waves equation}
\begin{frame}\frametitle{P-waves equation}
Taking divergence to (\ref{eq:waveHelm})
\[\nabla\cdot \left( \pardiff{^2 \vec{u}}{t^2} \right)= (\lambda +2\mu) \nabla\cdot \nabla \varphi - \mu\nabla\cdot\nabla\times \vec{\psi} \enspace , \]
we finally get
\begin{equation}
\nabla^2 \varphi = \frac{1}{\frac{\lambda + 2\mu}{\rho}} \pardiff{^2 \varphi}{t^2} \enspace ,
\label{eq:pWave}
\end{equation}
with speed of propagation
\[v_P := \sqrt{\frac{\lambda + 2\mu}{\rho}}\]
\end{frame}

\begin{frame}\frametitle{P-wave polarization}
\begin{figure}[H]
\centering
\includemedia[
  width=0.8\textwidth,
  height=0.6\linewidth,
  activate=pageopen,
  addresource=vids/P-0.flv,
  flashvars={source=vids/P-0.flv}
]{}{VPlayer.swf}
\caption{Particle motion in a P wave.}
\label{vid:P0}
\end{figure}
\end{frame}

% S-waves
\subsection{S-waves equation}
\begin{frame}\frametitle{S-waves equation}
Taking rotational to (\ref{eq:waveHelm})
\[\nabla\times \left( \pardiff{^2 \vec{u}}{t^2} \right)= (\lambda +2\mu) \nabla\times \nabla \varphi - \mu\nabla\times\nabla\times \vec{\psi} \enspace , \]
we finally get
\begin{equation}
\nabla^2 \vec{\psi} = \frac{1}{\frac{\mu}{\rho}} \pardiff{^2 \vec{\psi}}{t^2} \enspace ,
\label{eq:SWave}
\end{equation}
with speed of propagation
\[v_S := \sqrt{\frac{\mu}{\rho}}\]
\end{frame}

\begin{frame}\frametitle{S-wave polarization}
\begin{figure}[H]
\centering
\includemedia[
  width=0.8\textwidth,
  height=0.6\linewidth,
  activate=pageopen,
  addresource=vids/SV-0.flv,
  flashvars={source=vids/SV-0.flv}
]{}{VPlayer.swf}
\caption{Particle motion in a SV wave.}
\label{vid:SV0}
\end{figure}
\end{frame}

%
\begin{frame}\frametitle{References}
\begin{itemize}
\item Michael A. Slawinski. Waves and rays in Elastic Continua. Second Edition, 2007.

\item Wikipedia community. Onda (f\'isica) [on line]. Wikipedia, La enciclopedia libre, 2010 ; 22 November 2010.

\item George B. Arfken \& Hans. J. Weber. Mathematical Methods for Physicists. Elsevier Academic Press, 6th Edition, San Diego, 2005.
\end{itemize}
\end{frame}

\end{document}