\documentclass[aps,notitlepage,nofootinbib,11pt]{revtex4-1}

% linking references
\usepackage{hyperref}
\hypersetup{
  breaklinks=true,
  colorlinks=true,
  linkcolor=blue,
  filecolor=magenta,
  urlcolor=cyan,
}

%%% symbols, notations, etc.
\usepackage{physics,braket,bm,commath,amssymb} % physics and math
\renewcommand{\t}{\text} % text in math mode
\newcommand{\f}[2]{\dfrac{#1}{#2}} % shorthand for fractions
\newcommand{\p}[1]{\left(#1\right)} % parenthesis
\renewcommand{\sp}[1]{\left[#1\right]} % square parenthesis
\renewcommand{\set}[1]{\left\{#1\right\}} % curly parenthesis
\renewcommand{\v}{\bm} % bold vectors
\renewcommand{\c}{\cdot} % inner product
\newcommand{\bk}{\braket} % shorthand for braket notation
\newcommand{\Bk}{\Braket} % shorthand for braket notation

\renewcommand{\d}{\text{d}} % "d" for integration measure
\newcommand{\g}{\text{g}} % ground / excited electronic states
\newcommand{\e}{\text{e}}

\newcommand{\B}{\mathcal{B}}
\newcommand{\D}{\mathcal{D}}
\newcommand{\E}{\mathcal{E}}
\newcommand{\G}{\mathcal{G}}
\newcommand{\I}{\mathcal{I}}
\newcommand{\J}{\mathcal{J}}
\renewcommand{\L}{\mathcal{L}}
\renewcommand{\O}{\mathcal{O}}
\renewcommand{\P}{\mathcal{P}}
\newcommand{\Q}{\mathcal{Q}}

\usepackage{dsfont} % for identity operator
\newcommand{\1}{\mathds{1}}

\usepackage[inline]{enumitem} % for inline enumeration

%%% figures
\usepackage{graphicx} % for figures
\usepackage{grffile} % help latex properly identify figure extensions
\usepackage[caption=false]{subfig} % subfigures (via \subfloat[]{})
\graphicspath{{./figures/squeezing/}} % set path for all figures

% for strikeout text
% normalem included to prevent underlining titles in the bibliography
\usepackage[normalem]{ulem}

% for leaving notes in the text
\newcommand{\note}[1]{\textcolor{red}{#1}}

\begin{document}

\title{Spin-orbit-coupling-induced squeezing in the optical lattice
  clock}

\author{Michael A. Perlin}

\maketitle

These are some notes about trying to induce spin squeezing in an
optical lattice clock by combining spin-orbit coupling, interactions,
and external drives.  We assume, for now, that
\begin{enumerate*}[label=(\roman*)]
\item atoms are fermionic in nature with an alkali-earth(-like)
  electronic structure,
\item atoms are nuclear-spin-polarized, and
\item the optical lattice is quasi-one-dimensional, with tight
  (i.e.~ground-state) confinement in transverse directions.
\end{enumerate*}

\section{Spin-orbit coupling}

We start with two-level atoms loaded into the ground band of an
optical lattice, and consider interrogating these atoms by a linearly
polarized plane-wave laser tuned to the relevant electronic (atomic)
transition, with wavenumber projection $\phi$ onto the lattice axis.
After performing a gauge transformation which shifts the on-axis
momenta of ground (excited) states by $\phi/2$ ($-\phi/2$), and
eliminating (i.e.~turning off) the interrogation laser, one can arrive
at the Hamiltonian
\begin{align}
  H_{\t{SOC}}
  = \sum_{q,s} E_{qs\phi} \hat c_{qs}^\dag \hat c_{qs}
  \approx -2 J_0\sum_{q,s} \cos\p{q+s\phi/2}
  \hat c_{qs}^\dag \hat c_{qs}
  \label{eq:H_SOC_start}
\end{align}
where $q$ indexes quasi-momentum along the lattice axis,
$s\in\set{\g\leftrightarrow-1,\e\leftrightarrow1}$ labels the
electronic state, $J_0$ is the (positive) ground-band tunneling rate,
$c_{q\sigma}$ is a fermionic annihilation operator, and we work in
units with the lattice spacing $a=1$.  Defining
\begin{align}
  \1_q \equiv \hat c_{q,\g}^\dag \hat c_{q,\g}
  + \hat c_{q,\e}^\dag \hat c_{q,\e},
  &&
  \sigma_q^j \equiv \sum_{\alpha,\beta}
  \hat c_{q\alpha}^\dag \sigma^j_{\alpha\beta} \hat c_{q\beta},
  \label{eq:pseudospin}
\end{align}
for Pauli matrices $\sigma^j$ (i.e.~such that $\sigma_q^j$ is a
pseudo-spin-1/2 Pauli operator on the electronic degrees of freedom)
and expanding the cosine in \eqref{eq:H_SOC_start}, we thus find
\begin{align}
  H_{\t{SOC}}
  = -\sum_q \p{\epsilon_q \1_q + \f12 h_q \sigma_q^z},
  &&
  \epsilon_q \equiv 2J_0 \cos\p{\phi/2} \cos q,
  &&
  h_q \equiv -4J_0 \sin\p{\phi/2} \sin q.
\end{align}
When all dynamics conserve the occupations of all quasi-momenta, the
first term in this Hamiltonian merely contributes a constant energy
shift which we can safely neglect, leaving us with the effective
inhomogeneous-field Hamiltonian
\begin{align}
  H_{\t{SOC}} = -\sum_q h_q s_q^z,
  &&
  s_q^z \equiv \f12 \sigma_q^z
  \label{eq:H_SOC}
\end{align}

\section{Interactions}

At ultracold temperatures inter-atomic interactions are dominated by
$s$-wave collisions, which are captured by the Hamiltonian
\begin{align}
  H_{\t{int}} = G \int \d^3x~
  \hat\psi_\e^\dag\p{x} \hat\psi_\g^\dag\p{x}
  \hat\psi_\g\p{x} \hat\psi_\e\p{x},
  &&
  G \equiv \f{4\pi a_{\e\g^-}}{m_A},
  \label{eq:H_int_full}
\end{align}
where $\hat\psi_\sigma$ is a fermionic field operator for atoms in
electronic state $\sigma\in\set{\g,\e}$, $a_{eg}^-$ is an scattering
length, and $m_A$ is the mass of a single atom.  Considering only
occupation of the ground band in a lattice, we can expand the field
operators as
\begin{align}
  \hat\psi_\sigma\p{x} = \sum_q \phi_q\p{x} \hat c_{q\sigma},
\end{align}
for momentum-space (Bloch) wavefunctions $\phi_q$ and fermionic
annihilation operators $\hat c_{q\sigma}$.  The interaction
Hamiltonian then becomes
\begin{align}
  H_{\t{int}} = G \sum_{p,q,r,s} K^{pq}_{rs}
  \hat c_{r,\e}^\dag \hat c_{s,\g}^\dag \hat c_{q,\g} \hat c_{p,\e},
  &&
  K^{pq}_{rs} \equiv \int \d^3x~
  \phi_r\p{x}^* \phi_s\p{x}^* \phi_q\p{x} \phi_p\p{x}.
\end{align}
In a lattice with $L$ sites centered on positions $x_j$ (i.e.~for
$j=1,\cdots L$ indexing lattice site) and localized (Wannier)
wavefunctions $w_j$, we can expand
$\phi_p\p{x}=L^{-1/2}\sum_je^{-ipx_j}w_j\p{x}$, which implies
\begin{align}
  K^{pq}_{rs} = L^{-2} \sum_{j,k,\ell,m} \int \d^3x~
  \exp\sp{-i\p{px_j+qx_k-rx_\ell-sx_m}}
  w_\ell\p{x}^* w_m\p{x}^* w_k\p{x} w_j\p{x}.
\end{align}
If we now assume that we can neglect integrals without $j=k=\ell=m$,
which is equivalent to neglecting inter-site interactions and
interaction-assisted hopping, then we have
\begin{align}
  K^{pq}_{rs} \approx L^{-2} \sum_j \int \d^3x~
  \exp\sp{-i\p{p+q-r-s}x_j} \abs{w_j\p{x}}^4,
\end{align}
where a stationary phase approximation now forces $p+q-r-s=0$ (mod
$2\pi$ in units with the lattice spacing $a=1$), which is equivalent
to conservation of total momentum.  In terms of the Kronecker delta
$\delta_{p+q,r+s}$ enforcing $p+q=r+s$, it follows that
\begin{align}
  K^{pq}_{rs} \approx \delta_{p+q,r+s} L^{-2}
  \sum_j \int \d^3x~ \abs{w_j\p{x}}^4
  = \delta_{p+q,r+s} L^{-1} \int \d^3x~ \abs{w_0\p{x}}^4,
\end{align}
which motivates the definition
\begin{align}
  U \equiv G \int \d^3x~ \abs{w_0\p{x}}^4,
\end{align}
in order to express the interaction Hamiltonian in the simple form
\begin{align}
  H_{\t{int}} = \f{U}{L} \sum_{p,q,r,s}
  \delta_{p+q,r+s} \hat c_{r,\e}^\dag \hat c_{s,\g}^\dag
  \hat c_{q,\g} \hat c_{p,\e}.
  \label{eq:H_int_uniform}
\end{align}

\section{Collective spin model}

If the single-particle energy spacings are large compared to the
strength of inter-particle interactions, or equivalently if
$J_0\gtrsim U$, then by the secular approximation we can neglect terms
in $H_{\t{int}}$ which do not conserve the sum of single-particle
energies.  By solving this single-particle energy conservation
condition, one finds that we must have $\set{p,q}=\set{r,s}$; that is,
atoms in different clock states can only interact via
\begin{enumerate*}[label=(\roman*)]
\item direct density-density terms, and
\item terms which exchange their momenta.
\end{enumerate*}
The surviving terms in \eqref{eq:H_int_uniform} are thus
\begin{align}
  H_{\t{int}}
  = \f{U}{L} \sum_{p,q}
  \p{\hat c_{p,\e}^\dag \hat c_{q,\g}^\dag \hat c_{q,\g} \hat c_{p,\e}
    + \hat c_{q,\e}^\dag \hat c_{p,\g}^\dag \hat c_{q,\g} \hat c_{p,\e}}
  = \f{U}{L} \sum_{p,q}
  \p{\hat c_{q,\g}^\dag \hat c_{q,\g} \hat c_{p,\e}^\dag \hat c_{p,\e}
    - \hat c_{q,\e}^\dag \hat c_{q,\g} \hat c_{p,\g}^\dag \hat c_{p,\e}},
\end{align}
where we can use the single-particle pseudo-spin-1/2 Pauli operators
in \eqref{eq:pseudospin} to write
\begin{align}
  H_{\t{int}} = \f{U}{L} \sum_{p,q}
  \sp{\p{\f{\1_q-\sigma_q^z}{2}} \p{\f{\1_p+\sigma_p^z}{2}}
    - \sigma_q^+ \sigma_p^-}
  = \f{U}{L} \sum_{p,q}\f14\p{\1_q \1_p - \v\sigma_q\c\v\sigma_p},
  \label{eq:H_int_pauli}
\end{align}
with
\begin{align}
  \v{\sigma}_p \equiv \p{\sigma_p^x,\sigma_p^y,\sigma_p^z}.
\end{align}
For a fixed total particle number $N$, the identity operators in
\eqref{eq:H_int_pauli} contribute only a global shift in energy, which
allows us to more simply write
\begin{align}
  H_{\t{int}} = - \f{U}{L} \v S\c\v S,
  &&
  \v S \equiv \f12 \sum_p \v{\sigma}_p.
\end{align}
This Hamiltonian has electronic eigenstates $\set{\ket{Sm}}$ with
total (pseudo-)spin $S$ and projection $m$ onto a quantization axis;
the corresponding energies are
$\bk{Sm|H_{\t{int}}|Sm}=-\p{U/L}S\p{S+1}$.  In particular, the
ground-state $S=N/2$ manifold is spanned by the Dicke states
\begin{align}
  \ket{m} \equiv \ket{N/2,m} \propto S_+^{N/2+m} \ket{\g}^{\otimes N},
  &&
  S_+ \equiv \sum_n \sigma_n^+,
  \label{eq:dicke_states}
\end{align}
where $n$ indexes an individual atom,
$\sigma_n^+\equiv\hat c_{n,\e}\hat c_{n,\g}$ is an individual
spin-raising operator, and $N/2+m=0,1,\cdots,N$ is the number of
electronic state excitations in the state $\ket{m}$
\cite{swallows2011suppression}.  In words, the Dicke state $\ket{m}$
is a uniform superposition of all states with $N/2+m$ total electronic
excitations.

\section{Spin squeezing and one-axis twisting}
\label{sec:OAT}

In total, free evolution of atoms on a lattice is governed by the
Hamiltonian
\begin{align}
  H_{\t{free}}
  = H_{\t{int}} + H_{\t{SOC}}
  = -\f{U}{L} \v S\c\v S - \sum_n h_n s_n^z,
\end{align}
for $n$ indexing an individual atom.  When the ``local'' fields $h_n$
are small in magnitude compared to the collective spin gap $\eta U$
and we initialize all atoms in the ground-state subspace of
$H_{\t{int}}$, we can treat the action of the spin-orbit coupling
Hamiltonian perturbatively, which yields the effective free-evolution
Hamiltonian (see Appendix \ref{sec:squeezing_derivation} or Peiru's
notes)
\begin{align}
  H_{\t{free,eff}} = -\bar h S_z + \chi S_z^2,
\end{align}
where
\begin{align}
  \bar h \equiv \f1N \sum_n h_n,
  &&
  \tilde h^2 \equiv \f1N \sum_n \p{h_n - \bar h}^2,
  &&
  \chi \equiv \f{\tilde h^2}{\p{N-1}\eta U}.
\end{align}
At temperatures $T\gg J_0$, the mean effective field $\bar h=0$, while
for $T\sim J_0$ the collective rotation due to the $S_z$ term can be
eliminated by use of a rotating frame.  The free-evolution Hamiltonian
thus simplifies further to the one-axis twisting Hamiltonian
\begin{align}
  H_{\t{OAT}}^z = \chi S_z^2,
  \label{eq:H_OAT}
\end{align}
which generates spin squeezing dynamics with metrological
applications.  Specifically, one-axis twisting allows for measurements
of collective spin in the plane orthogonal to the mean spin vector
$\bk{\v S}$ with a spin fluctuation noise floor which scales as
$\sim1/N^{2/3}$ (additional info in Peiru's notes\note{(?)}).

An example set of parameters for realizing one-axis twisting via
$H_{\t{OAT}}^z$ with strontium-87 in a 1-D magic-wavelength lattice is
provided in Table \ref{tab:parameters}, along with the optimal
squeezing time
$t_{\t{opt}}^{\t{OAT}}\sim N^{-2/3}\chi^{-1}\sim\eta
N^{1/3}=N^{4/3}/L$.  Lattice depths are provided in units of the
lattice recoil energy $E_R$.

\begin{table}[h]
  \centering
  \caption{Example parameters for spin squeezing via one-axis
    twisting.}
  \label{tab:parameters}
  \begin{tabular}{|l|c|l|}
    \hline
    Parameter & Symbol & Value \\ \hline\hline
    Primary lattice depth & $V_0$ & 5 $E_R$ \\
    Transverse lattice depths & $V_T$ & 60 $E_R$ \\
    SOC strength & $\phi$ & $\pi/25$ \\
    Lattice sites & $L$ & 100 \\
    Atom number & $N$ & 100 \\ \hline\hline
    Tunneling rate & $J_0$ & $\approx230\times2\pi$ Hz \\
    On-site interaction strength & $U$ & $\approx1.5\times2\pi$ kHz \\
    Twisting strength & $\chi$ & $\approx11\times2\pi$ mHz \\
    Optimal OAT squeezing time & $t_{\t{opt}}^{\t{OAT}}$
    & $\approx0.70$ seconds \\ \hline
  \end{tabular}
\end{table}

\section{Two-axis twisting: continuous drive}
\label{sec:continuous_drive}

We can go beyond the $\sim1/N^{2/3}$ one-axis twisting noise floor and
achieve an improved $\sim1/N$ noise floor via so-called two-axis
twisting, which can be achieved with external driving protocols.  By
turning on a clock laser resonant on the electronic transition of the
atoms, we can realize the Hamiltonian
\begin{align}
  H_{\t{drive}} = -\Omega \sum_n s_n^x + H_{\t{OAT}}^z
  = -\Omega S_x + \chi S_z^2,
\end{align}
where the drive strength $\Omega$ may generally depend on time, but
must always be much smaller in magnitude than the collective spin gap
$\eta U$ in order preserve the validity of the effective one-axis
twisting Hamiltonian (see Appendix \ref{sec:squeezing_derivation}).
Following the prescription in ref.~\cite{huang2015twoaxis} we now
modulate the drive as $\Omega\p{t}=\beta\omega\cos\p{\omega t}$ with
$\omega\gg N\chi$, and move into the rotating frame of
$-\Omega\p{t}S_x$.  After a single secular approximation which relies
only on $\omega\gg N\chi$, this procedure results in the effective
Hamiltonian
\begin{align}
  H_{\t{drive,eff}}^{\t{mod}}
  = \f{\chi}{2} \p{\sp{\J_0\p{2\beta}+1} S_z^2
    - \sp{\J_0\p{2\beta}-1} S_y^2},
\end{align}
where $\J_0$ is the zero-order Bessel function of the first kind.
Choosing a modulation index $\beta$ such that $\J_0\p{2\beta}=1/3$ or
$\J_0\p{2\beta}=-1/3$ then respectively results in the two-axis
twisting Hamiltonians
\begin{align}
  H_{\t{TAT}}^{z,x}
  = \f{\chi}{3} \p{2 S_z^2 + S_y^2}
  \simeq \f{\chi}{3} \p{S_z^2 - S_x^2},
  &&
  H_{\t{TAT}}^{y,x}
  = \f{\chi}{3} \p{S_z^2 + 2 S_y^2}
  \simeq \f{\chi}{3}\p{S_y^2 - S_x^2},
  \label{eq:H_TAT_drive}
\end{align}
where $\simeq$ denotes equality up to a global energy shift.  Given
the set of parameters in Table \ref{tab:parameters}, the two-axis
twisting Hamiltonian $H_{\t{TAT}}^{z,x}$ can be achieved with a drive
frequency $\omega=\abs{\eta U\chi}^{1/2}\approx41\times2\pi$ Hz and
modulation index $\beta\approx0.906$, and has an optimal squeezing
time of $t_{\t{opt}}^{\t{TAT}}\approx0.89$ seconds.  The figure of
merit for squeezing is the normalized minimal variance of spin in the
plane orthogonal to the mean spin vector $\bk{\v S}$:
\begin{align}
  \xi^2 \equiv \f{N}{\abs{\bk{\v S}}^2}
  \min_{\hat{\v n}\perp\bk{\v S}} \bk{\p{\v S\c\hat{\v n}}^2}
\end{align}
for $\abs{\hat{\v n}}=1$.  A comparison of this squeezing parameter
through $H_{\t{OAT}}^z$ and $H_{\t{TAT}}^{z,x}$ for the initial state
$\ket{Y}\equiv\bigotimes_n\p{\ket{\g}_n+i\ket{\e}_n}/\sqrt2$ via the
parameters in Table \ref{tab:parameters} is provided in Figure
\ref{fig:squeezing_comparison_TAT}.

\begin{figure}
  \centering \includegraphics{squeezing_comparison_TAT.pdf}
  \caption{Comparison of squeezing through $H_{\t{OAT}}^z$ and
    $H_{\t{TAT}}^{z,x}$ via the parameters in Table
    \ref{tab:parameters} and the continuous two-axis twisting protocol
    with $\omega\approx\abs{\eta U\chi}^{1/2}$ and $\beta=0.906$.}
  \label{fig:squeezing_comparison_TAT}
\end{figure}

\section{Two-axis twisting: pulsed drive}

Two-axis twisting can also be achieved using the pulsed-drive sequence
described in ref.~\cite{liu2011spin}.  This sequence requires the
drive strength $\Omega$ much greater than the collective spin gap, or
$\abs{\Omega}\gg\eta\abs{U}$, which allows us to generate collective
spin rotations of the form $\exp\p{\pm i\theta S_x}$ with short pulses
during which we can neglect any free evolution of the atoms.  Thus
\begin{enumerate*}[label=(\roman*)]
\item acting with $\exp\sp{i\p{\pi/2}S_x}$,
\item waiting for a time $2\tau/3$,
\item acting with $\exp\sp{-i\p{\pi/2}S_x}$, and
\item waiting for a time $\tau/3$
\end{enumerate*}
realizes the unitary
\begin{align}
  U_\tau
  &= \exp\p{-i\f13\tau\chi S_z^2} \exp\p{-i\f{\pi}{2}S_x}
  \exp\p{-i\f23\tau\chi S_z^2} \exp\p{i\f{\pi}{2}S_x} \\
  &= \exp\p{-i\f13\tau\chi S_z^2} \exp\p{-i\f23\tau\chi S_y^2},
\end{align}
where if $\tau\chi\ll1$, then
\begin{align}
  U_\tau \approx \exp\sp{-i\f13\tau\chi\p{S_z^2 + 2S_y^2}}
  = \exp\p{-i\tau H_{\t{TAT}}^{y,x}}.
\end{align}
Such a sequence thus generates evolution which is equivalent to simply
evolving for a time $\tau$ under the two-axis twisting Hamiltonian
$H_{\t{TAT}}^{y,x}$.

\section{Benchmarking}

For small system sizes, we can verify the validity of the effective
one- and two-axis twisting Hamiltonians via direct simulations of a
single-band Fermi-Hubbard (FH) model, using the spin-orbit coupling
Hamiltonian $H_{\t{SOC}}$ and interaction Hamiltonian $H_{\t{int}}$
respectively given in \eqref{eq:H_SOC_start} and
\eqref{eq:H_int_full}.  Figure \ref{fig:squeezing_comparison_FH} shows
a comparison of the squeezing parameter $\xi^2$ after evolution of the
initial state $\ket{Y}$ for $N=8$ particles in a 1-D lattice with
$L=8$ sites (and remaining system parameters as given in the top half
of Table \ref{tab:parameters}) after evolution under
\begin{enumerate*}[label=(\roman*)]
\item the one-axis twisting Hamiltonian $H_{\t{OAT}}^z$,
\item the two-axis twisting Hamiltonian $H_{\t{OAT}}^{z,x}$,
\item free evolution of the Fermi-Hubbard model under
  $H_{\t{SOC}}+H_{\t{int}}$, and
\item driven evolution of the Fermi-Hubbard model using the
  continuous-drive protocol in Section \ref{sec:continuous_drive} with
  drive frequency $\omega=\abs{\eta U\chi}^{1/2}$ and modulation index
  $\beta=0.906$.
\end{enumerate*}
These simulation results show essentially perfect agreement between
the Fermi-Hubbard model and the one- and two-axis twisting
Hamiltonians for the given parameters.

\begin{figure}
  \centering
  \includegraphics{squeezing_comparison_FH.pdf}
  \caption{Benchmarking squeezing under the one- and two-axis
    Hamiltonians $H_{\t{OAT}}^z$ and $H_{\t{TAT}}^{z,x}$ against
    direct simulations of the Fermi-Hubbard model with $N=L=8$ and the
    remaining system parameters as given in the top half of Table
    \ref{tab:parameters}.}
  \label{fig:squeezing_comparison_FH}
\end{figure}

\section{Last thoughts}

It may be possible to further enhance the twisting strength $\chi$ by
placing the atoms in an optical cavity, as in
ref.~\cite{hu2017vacuum}.  Both squeezing times and twisting strengths
might also be further enhanced by using a 2-D lattice, although more
benchmarking is necessary to verify the validity of the collective
spin model in 2-D.  Figure \ref{fig:squeezing_comparison_2D} shows a
comparison of squeezing strengths via one- and two-axis squeezing in a
2-D lattice with $100\times100$ sites.

\begin{figure}
  \centering
  \includegraphics{squeezing_comparison_2D.pdf}
  \caption{Squeezing via one- and two-axis twisting in a $V_0=7E_R$
    depth 2-D lattice with $100\times100$ sites at unit filling
    ($N=10^4$), transverse confinement depth $V_T=80E_R$, and
    spin-orbit coupling strength $\phi=\pi/25$.}
  \label{fig:squeezing_comparison_2D}
\end{figure}

\newpage
\appendix

\section{Effective spin squeezing in the presence of a weak drive}
\label{sec:squeezing_derivation}

Suppose we have a Hamiltonian of the form
\begin{align}
  H = H_0 + V,
  &&
  H_0 = - \f{U}{L} \v S\c\v S,
  &&
  V = - \sum_n h_n s_n^z - \Omega S_x,
\end{align}
and we consider $N$-particle states initially in the ground-state
manifold $\G_0$ of $H_0$, which have total spin $S\equiv N/2$.  If the
largest eigenvalue of $V$ is smaller in magnitude than half of the
collective spin gap $N\abs{U}/L=\eta\abs{U}$, i.e.~the energy gap
under $H_0$ between $\G_0$ and its orthogonal complement $\E_0$, then
we can formally develop a perturbative treatment for the action of $V$
on $\G_0$.  Such a treatment yields an effective Hamiltonian on $\G_0$
of the form $H_{\t{eff}}=\sum_pH_{\t{eff}}^{(p)}$, where
$H_{\t{eff}}^{(p)}$ is order $p$ in $V$.  Letting $\P_0$ ($\Q_0$) be a
projector onto $\G_0$ ($\E_0$) and $X$ denote any operator on
$\G_0\cup\E_0$ (i.e.~the entire Hilbert space), we define the
superoperators
\begin{align}
  \D X \equiv \P_0 X \P_0 + \Q_0 X \Q_0,
  &&
  \O X \equiv \P_0 X \Q_0 + \Q_0 X \P_0,
\end{align}
which select the diagonal ($\D$) and off-diagonal ($\O$) parts of $X$
with respect to $\G_0$ and $\E_0$, and
\begin{align}
  \L X \equiv \sum_{\alpha,\beta}
  \f{\op{\alpha}\O X\op{\beta}}{E_\alpha-E_\beta},
  &&
  \t{where}
  &&
  H_0 = \sum_\alpha E_\alpha \op\alpha.
\end{align}
The first few terms in the expansion of the effective Hamiltonian
$H_{\t{eff}}$ are then, as derived in
ref.~\cite{bravyi2011schrieffer},
\begin{align}
  H_{\t{eff}}^{(0)} = \P_0 H_0 \P_0,
  &&
  H_{\t{eff}}^{(1)} = \P_0 V \P_0,
  &&
  H_{\t{eff}}^{(2)} = -\f12 \P_0 \sp{\O V,\L V} \P_0.
  \label{eq:H_eff_012}
\end{align}
If we add a constant to $H_0$ such that $E_\psi=0$ for all
$\ket\psi\in\G_0$, or equivalently we measure all energies relative to
that of the ground-state manifold $\G_0$ with respect to $H_0$, it
immediately follows that $H_{\t{eff}}^{(0)}=0$.  To calculate
$H_{\t{eff}}^{(1)}$, we note that the ground-state manifold $\G_0$ is
spanned by the Dicke states $\ket{m}$ defined in
\eqref{eq:dicke_states}, in terms of which we can expand the
collective spin-$z$ operator as $S_z=\sum_mm\op{m}$.  We can likewise
expand the collective spin-$x$ operator $S_x$ in terms of $x$-oriented
Dicke states $\ket{m_x}$ as $S_x=\sum_mm\op{m_x}$.  The ground-state
projector $\P_0$ onto $\G_0$ can be expanded in either basis as
$\P_0=\sum_m\op{m}=\sum_m\op{m_x}$.  Defining the mean and residual
fields
\begin{align}
  \bar h \equiv \f1N \sum_n h_n,
  &&
  b_n \equiv h_n - \bar h,
\end{align}
we can then write
\begin{align}
  V = -\sum_n \p{b_n+\bar h} s_n^z - \Omega S_x
  = -\sum_n b_n s_n^z - \bar h S_z - \Omega S_x,
\end{align}
and in turn
\begin{align}
  H_{\t{eff}}^{(1)}
  = \P_0\p{-\sum_n b_n s_n^z - \bar h S_z - \Omega S_x} \P_0
  = -\sum_n b_n \P_0 s_n^z\P_0 - \bar h S_z - \Omega S_x,
\end{align}
where we used the fact that $\P_0 S_{j=z,x} \P_0 = S_j$.  By
construction, the residual fields are mean-zero, i.e.~$\sum_nb_n=0$.
Using the particle-exchange symmetry of the Dicke states, we can thus
expand
\begin{align}
  \sum_n b_n \P_0 s_n^z \P_0
  = \sum_{n,m,m'} b_n \op{m} s_n^z \op{m'}
  = \sum_n b_n \sum_{m,m'} \op{m} s_1^z \op{m'}
  = 0,
\end{align}
which implies
\begin{align}
  H_{\t{eff}}^{(1)} = - \bar h S_z - \Omega S_x.
\end{align}
To calculate the second-order effective Hamiltonian
$H_{\t{eff}}^{(2)}$, we let $\B_0\p{\E_0}$ denote an eigenbasis of
$H_0$ for the excited subspace $\E_0$, define the operator
\begin{align}
  \I \equiv \sum_{\ket\alpha\in\B_0\p{\E_0}} \f{\op\alpha}{E_\alpha},
\end{align}
which sums over projections onto excited states with corresponding
energetic suppression factors, and expand
\begin{align}
  \L X = \O\p{\L X}
  = \Q_0 \L X \P_0 + \P_0 \L X \Q_0
  = \I X \P_0 - \P_0 X \I.
\end{align}
The expression for $H_{\t{eff}}^{(2)}$ in \eqref{eq:H_eff_012} then
simplifies to
\begin{align}
  H_{\t{eff}}^{(2)}
  = -\f12 \P_0 \p{\sp{\O V, \I V \P_0} - \sp{\O V, \P_0 V \I}} \P_0
  = -\P_0 V \I V \P_0.
\end{align}
The only part of $V$ which is off-diagonal with respect to the ground-
and excited-state manifolds $\G_0$ and $\E_0$ is $-\sum_nb_ns_n^z$,
and the individual operators in this term can only change the total
spin $S$ by at most 1.  It is therefore sufficient to expand $\I$ in a
basis for states with total spin $S=N/2-1$, which is provided by the
spin-wave states
\begin{align}
  \ket{mk}
  \equiv \ket{N/2-1,m,k}
  \equiv {N-1 \choose \p{N/2-m}\p{N/2-m+1}}^{-1/2}
  \sum_{n=1}^N e^{2\pi ikn/N} s_n^+ \ket{N/2,m-1},
\end{align}
for $k=1,2,\cdots,N-1$ \cite{swallows2011suppression}.  Using the fact that all spin-$z$ operators preserve the projection of total spin onto the $z$ axis, we then have that
\begin{align}
  H_{\t{eff}}^{(2)}
  = -\f1{\eta U} \sum_{m,m',k,n,n'} b_n b_{n'}
  \Bk{m| s_n^z \op{m'k} s_{n'}^z |m} \op{m}.
  \label{eq:general_H_eff_2}
\end{align}
The relevant matrix elements between the Dicke states and the
spin-wave states are \cite{swallows2011suppression}
\begin{align}
  \bk{m|s_n^z|m'k}
  = e^{2\pi i k n/N} \sqrt{\f{(N/2)^2-m^2}{N^2 (N-1)}}~ \delta_{m,m'},
\end{align}
which implies
\begin{align}
  H_{\t{free,eff}}^{(2)}
  = -\f1{\eta U} \sum_m \f{(N/2)^2-m^2}{N^2 (N-1)} \op{m}
  \sum_{k,n,n'} b_n b_{n'} e^{2\pi ik\p{n-n'}/N}.
\end{align}
Using the fact that $\sum_nb_n=0$, we can expand
\begin{align}
  \sum_{k,n,n'} b_n b_{n'} e^{2\pi ik\p{n-n'}/N}
  = \sum_{n,n'} b_n b_{n'} \sum_{k=1}^{N-1} e^{2\pi ik\p{n-n'}/N}
  = \sum_{n,n'} b_n b_{n'} \sum_{k=0}^{N-1} e^{2\pi ik\p{n-n'}/N},
\end{align}
where the sum over $k$ vanishes for $n\ne n'$ and equals $N$ when
$n=n'$, so
\begin{align}
  \sum_{k,n,n'} b_n b_{n'} e^{2\pi ik\p{n-n'}/N}
  = N \sum_n b_n^2 = N^2 \tilde h^2,
  &&
  \tilde h^2 \equiv \f1N \sum_n b_n^2 = \f1N \sum_n \p{h_n - \bar h}^2.
  \label{eq:sum_knn}
\end{align}
We therefore have that
\begin{align}
  H_{\t{free,eff}}^{(2)}
  = -\sum_m \f{\p{N/2}^2-m^2}{\p{N-1}\eta U}~ \tilde h^2 \op{m},
\end{align}
where the term $\p{N/2}^2$ term contributes a global energy shift
which we can neglect, while the $m^2$ term is proportional to
$m^2\op{m}=S_z^2$.  In total, the effective Hamiltonian is thus
\begin{align}
  H_{\t{free,eff}} = - \bar h S_z - \Omega S_x + \chi S_z^2,
  &&
  \chi \equiv \f{\tilde h^2}{\p{N-1}\eta U}.
\end{align}

\bibliography{\jobname}

\end{document}


\documentclass{article}
\usepackage[intlimits]{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts,amstext,amsthm}
\usepackage{paralist}        % {inparaenum} environment
\usepackage{mathtools}       % {dcases} environment
\usepackage{wasysym}         % \clock
\usepackage[normalem]{ulem}  % \sout
\usepackage[usenames,dvipsnames]{xcolor} % Named colors
\usepackage{hyperref}
\usepackage{booktabs}
\usepackage[margin=2.5cm]{geometry}

\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{patterns}

% ~~ Styling ~~
\renewcommand{\geq}{\geqslant}
\renewcommand{\leq}{\leqslant}

\newcommand{\ignore}[1]{}
\newcommand{\nolabel}[1]{}
\newcommand{\set}[1]{\left\{ #1 \right\}}
% Set with condition and automatically scaled braces: {... | ...}.
\newcommand{\cset}[3][:]{\left\{#2 \,#1\, #3\right\}}

\renewcommand{\Pr}{{\sf P}}           % Probability measure.
\DeclareMathOperator{\EV}{{\sf E}}    % Expected value.
\DeclareMathOperator{\Var}{{\sf Var}} % Variance.
\DeclareMathOperator{\Cov}{{\sf Cov}} % Covariance.
\DeclareMathOperator{\SE}{{\sf SE}}   % Standard error.
\DeclareMathOperator{\Hyp}{\mathcal{H}}
\DeclareMathOperator{\DNormal}{\mathcal{N}} % Normal distribution.

% ~~ Linear Algebra ~~
\renewcommand{\vec}[1]{\boldsymbol{#1}}
\newcommand{\One}{\mathchoice{\rm 1\mskip-4.2mu l}{\rm 1\mskip-4.2mu l}{\rm 1\mskip-4.6mu l}{\rm 1\mskip-5.2mu l}}
\newenvironment{algorithm}[1][]{\paragraph*{Algorithm#1.}}{\vspace{1ex}}

% ~~ Paper-specific ~~
\newcommand{\hlambda}{\hat{\lambda}}
\newcommand{\hmu}{\hat{\mu}}
\newcommand{\htau}{\hat{\tau}}
\newcommand{\ESS}{\mathrm{ESS}}
\newcommand{\PFA}{\mathrm{PFA}}
\newcommand{\PMS}{\mathrm{PMS}}
\newcommand{\PrFA}{\Pr _\mathrm{FA}}
\newcommand{\PrMS}{\Pr _\mathrm{MS}}

% Styling.
\hypersetup{
    colorlinks=true,%
    bookmarksnumbered=true,%
    bookmarksopen=true,%
    citecolor=blue,%
    urlcolor=blue,%
    unicode=true,           % enable unicode encoded PDF strings
    breaklinks=true         % allow links to break over lines by making
                            % links over multiple lines into PDF
                            % links to the same target
}

\begin{document}

\section*{Formulation.}

The objective of this project is to simulate target detection in a noisy environment.
The signal, $S_n$, $n \geq 1$, is assumed to be known and deterministic.
To model the environment we assume additive i.i.d.\ standard Gaussian noise $W_n$.
The observed process $X_n$, $n \geq 1$, is defined by
\begin{align*} \nolabel{eq:observed_process}
    X_n = \mu S_n + W_n,
\end{align*}
where $\mu$ is unknown (representing signal strength).
%Note that $X_n$ are independent $\DNormal(\mu S_n, 1)$.

We are now in position to formulate the hypothesis testing problem.
%
Let $\mu_0 = 0$, and $\mu_1 > \mu_0$ be given. We are interested in testing
\begin{align} \label{eq:model}
    \Hyp_0 : \mu = \mu_0
    \quad \text{vs.} \quad
    \Hyp_1 : \mu \geq \mu_1.
\end{align}
In what follows we will also need to introduce auxiliary hypotheses $\set{\Hyp_\theta : \mu = \theta }$.
%
It is not hard to see that the log-likelihood ratio (LLR) process between $\Hyp_\mu$ and $\Hyp_{\mu'}$ has the form
\begin{align} \label{eq:LLR:general}
    \lambda_n(\mu, \mu')
        &= (\mu - \mu') \sum_{i = 1}^{n} S_i X_i
        - \frac{\mu^2 - {\mu'}^2}{2} \sum_{i = 1}^{n} S_i^2.
\end{align}

\section*{Estimation and Stopping.}

Let $\hmu_n$ denote the unconstrained maximum likelihood estimator (MLE) of $\mu$:
\begin{align*} \nolabel{eq:mle:unconstrained}
    \hmu_n &= \max\set{0, \frac{\sum_{i = 1}^n S_i X_i}{\sum_{i = 1}^n S_i^2}}.
\end{align*}
Furthermore, let $\hmu_{n, j}$ be the constrained MLE's under $\Hyp_j$, $j = 0, 1$:
\begin{align*} \nolabel{eq:mle:constrained}
    \hmu_{n, 0} = \mu_0 = 0, \quad
    \hmu_{n, 1} = \max \set{\mu_1, \hmu_n}.
\end{align*}

The adaptive versions of log-likelihood ratio \eqref{eq:LLR:general} are given by
\begin{align} \label{eq:LLR:adaptive}
    \hlambda_{n, j}
        &= \sum_{i = 1}^{n} (\hmu_{i - 1} - \hmu_{n, j}) S_i X_i
        - \frac{1}{2} \sum_{i = 1}^{n} (\hmu_{i - 1}^2 - \hmu_{n, j}^{2}) S_i^2 \\
        %&= \sum_{i = 1}^{n} \hmu_{i - 1} S_i (X_i - \hmu_{i - 1} S_i / 2)
        %- \hmu_{n, j} \sum_{i = 1}^{n} S_i X_i
        %+ \frac{\hmu_{n, j}^2}{2} \sum_{i = 1}^{n} S_i^2 \nonumber \\
        &= \sum_{i = 1}^{n} \hmu_{i - 1} S_i (X_i - \hmu_{i - 1} S_i / 2)
        + \lambda_n(0, \hmu_{n, j}) \nonumber
\end{align}
for $j = 0, 1$. The initial estimator $\hmu_0$ is chosen differently for $\hlambda_{n, 0}$ and $\hlambda_{n, 1}$, so that $\hlambda_{1, 0} = \hlambda_{1, 1} = 0$.

We consider the following decision rules.
The stopping time of the adaptive two-SPRT detection procedure is $\htau = \min\set{\htau_0,\htau_1}$, where
\begin{align} \label{eq:sprt:adaptive}
    \begin{split}
        \htau_0 &= \inf \cset{n \geq 1}{\hlambda_{n, 1} \geq a_0}, \\
        \htau_1 &= \inf \cset{n \geq 1}{\hlambda_{n, 0} \geq a_1}.
    \end{split}
\end{align}
The stopping time of the generalized two-SPRT detection procedure is $\tau = \min\set{\tau_0,\tau_1}$, where
\begin{align} \label{eq:sprt:adaptive}
    \begin{split}
        \tau_0 &= \inf \cset{n \geq 1}{\lambda_n(\hmu_n, \hmu_{n, 1}) \geq a_0}, \\
        \tau_1 &= \inf \cset{n \geq 1}{\lambda_n(\hmu_n, \hmu_{n, 0}) \geq a_1}.
    \end{split}
\end{align}

\paragraph*{Change of measure.}
Suppose $(t, d)$ is the decision rule, and let
\begin{align*}
    \PFA &= \Pr_{\mu_0} (d \neq 0), \\
    \PMS &= \sup_{\mu \geq \mu_1} \Pr_{\mu} (d \neq 1) = \Pr_{\mu_1} (d \neq 1)
\end{align*}
denote the probability of false alarm and probability of missed signal, respectively.
To facilitate assessing error probabilities, we employ the change of measure approach. Expected sample sizes $\ESS_j = \EV_{\mu_j}(t)$, $j = 0, 1$, do not require importance sampling. The following table summarizes the strategies (simulated signal strength vs.\ analyzed signal strength) in use:
\begin{center}
    \begin{tabular}{@{} l l l @{}} \toprule
                  & \multicolumn{2}{c}{Analyzed} \\ \cmidrule{2-3}
        Simulated & $\mu_0$           & $\mu_1$         \\ \midrule
        $\mu_0$   & $\ESS_0$          & $\PMS $         \\
        $\mu_1$   & $\PFA $           & $\ESS_1$        \\ \bottomrule
    \end{tabular}
\end{center}

\end{document}


\documentclass[twoside,10pt,a4paper]{article}
\input{macros.tex}

% For adding "DRAFT" to each page uncomment the following
% --------
\usepackage{eso-pic}
\makeatletter
\AddToShipoutPicture{%
  \setlength{\@tempdimb}{.5\paperwidth}%
  \setlength{\@tempdimc}{.5\paperheight}%
  \setlength{\unitlength}{1pt}%
  \put(\strip@pt\@tempdimb,\strip@pt\@tempdimc){%
    \makebox(0,0){\rotatebox{45}{\textcolor[gray]{0.9}%
      {\fontsize{6cm}{6cm}\selectfont{DRAFT}}}}%
  }%
}
\makeatother
% --------

\begin{document}
\DeclareGraphicsExtensions{.jpg,.pdf}

\title{Cam-Clay model based on Borja et al. 1997}
\author{Biswajit Banerjee}
\maketitle
\tableofcontents
\newpage

\section{Introduction}
Introduce the equations and how they differ from Fossum-Brannon.

\section{Quantities that are needed in a Uintah implementation}
\subsection{Elasticity}
The elastic strain energy density in Borja's model has the form
\[
  W(\Ve^e_v,\Ve^e_s) = W_\Tvol(\Ve^e_v) + W_\Tdev(\Ve^e_v, Ve^e_s)
\]
where
\[
   \Bal
    W_\Tvol(\Ve^e_v) & = -p_0\kappatilde\,\exp\left(-\frac{\Ve^e_v - \Ve^e_{v0}}{\kappatilde}\right) \\
    W_\Tdev(\Ve^e_v,\Ve^e_s) & =  \tfrac{3}{2}\,\mu\,(\Ve^e_s)^2
   \Eal
\]
where $\Ve^e_{v0}$ is the volumetric strain corresponding to a mean normal compressive stress $p_0$
(tension positive), $\kappatilde$ is the elastic compressibility index, and the shear modulus is given by
\[
  \mu = \mu_0 + \frac{\alpha}{\kappatilde}\,W_\Tvol(\Ve^e_v)
      = \mu_0 - \alpha p_0\,\exp\left(-\frac{\Ve^e_v - \Ve^e_{v0}}{\kappatilde}\right)
      = \mu_0 - \mu_\Tvol\,.
\]
The parameter $\alpha$ determines the extent of coupling between the volumetric and deviatoric
responses.  For consistency with isotropic elasticity, Rebecca Brannon suggests that $\alpha = 0$ (citation?).

The stress invariants $p$ and $q$ are defined as
\[
  \Bal
    p &= \Partial{W}{\Ve^e_v} = p_0\left[1 + \tfrac{3}{2}\,\frac{\alpha}{\kappatilde}\,(\Ve^e_s)^2\right]
         \exp\left(-\frac{\Ve^e_v - \Ve^e_{v0}}{\kappatilde}\right)
       = p_0\,\beta\,\exp\left(-\frac{\Ve^e_v - \Ve^e_{v0}}{\kappatilde}\right) \\
    q &= \Partial{W}{\Ve^e_s} = 3\left[\mu_0 - \alpha p_0\exp\left(-\frac{\Ve^e_v - \Ve^e_{v0}}{\kappatilde}\right)
         \right]\Ve^e_s  = 3\mu\,\Ve^e_s\,.
  \Eal
\]
The derivatives of the stress invariants are
\[
  \Bal
    \Partial{p}{\Ve^e_v} & = -\frac{p_0}{\kappatilde}
         \left[1 + \tfrac{3}{2}\,\frac{\alpha}{\kappatilde}\,(\Ve^e_s)^2\right]
         \,\exp\left(-\frac{\Ve^e_v - \Ve^e_{v0}}{\kappatilde}\right)
        = -\frac{p}{\kappatilde} \\
    \Partial{p}{\Ve^e_s} & = \Partial{q}{\Ve^e_v} = \frac{3\alpha p_0 \Ve^e_s}{\kappatilde}
         \,\exp\left(-\frac{\Ve^e_v - \Ve^e_{v0}}{\kappatilde}\right) = \frac{3\alpha p}{\beta \kappatilde}\,\Ve^e_s
         = \frac{3\mu_\Tvol}{\kappatilde}\,\Ve^e_s\\
    \Partial{q}{\Ve^e_s} & = 3 \left[\mu_0 - \alpha p_0
         \,\exp\left(-\frac{\Ve^e_v - \Ve^e_{v0}}{\kappatilde}\right) \right] = 3 \mu\,.
  \Eal
\]

\subsection{Plasticity}
For plasticity we use a Cam-Clay yield function of the form
\[
   f = \left(\frac{q}{M}\right)^2 + p(p-p_c)
\]
where $M$ is the slope of the critical state line and the consolidation pressure $p_c$ is an internal variable that
evolves according to
\[
   \frac{1}{p_c}\,\Deriv{p_c}{t} = \frac{1}{\lambdatilde - \kappatilde}\,\Deriv{\Ve^p_v}{t} \,.
\]
The derivatives of $f$ that are of interest are
\[
   \Bal
     \Partial{f}{p} & = 2p - p_c \\
     \Partial{f}{q} & = \frac{2q}{M^2} \,.
   \Eal
\]
If we integrate the equation for $p_c$ from $t_{n}$ to $t_{n+1}$, we can show that
\[
   (p_c)_{n+1} = (p_c)_n \exp\left[\frac{(\Ve_v^e)_\Trial - (\Ve_v^e)_{n+1}}{\lambdatilde - \kappatilde}\right] \,.
\]
The derivative of $p_c$ that is of interest is
\[
   \Partial{p_c}{(\Ve_v^e)_{n+1}} = -\frac{(p_c)_n}{\lambdatilde-\kappatilde}\,\exp\left[\frac{(\Ve^e_v)_\Trial - (\Ve_v^e)_{n+1}}{\lambdatilde-\kappatilde}\right] \,.
\]

\section{Why these quantities are needed: stress update based Rich Reguiero's notes}
The volumetric and deviatoric components of the elastic strain $\Beps^e$ are defined
as follows:
\[
   \BeT^e = \Beps^e - \tfrac{1}{3}\Ve^e_v\,\Bone = \Beps^e - \tfrac{1}{3}\Tr(\Beps^e)\,\Bone
   \quad \Tand \quad
   \Ve^e_s = \sqrt{\tfrac{2}{3}}\Norm{\BeT^e}{}  = \sqrt{\tfrac{2}{3}}\sqrt{\BeT^e:\BeT^e} \,.
\]
The stress tensor is decomposed into a volumetric and a deviatoric component
\[
   \Bsig = p\,\Bone + \sqrt{\tfrac{2}{3}}\, q\, \BnT \quad \text{with} \quad
   \BnT = \cfrac{\BeT^e}{\Norm{\BeT^e}{}} = \sqrt{\tfrac{2}{3}}\, \cfrac{\BeT^e}{\Ve^e_s} \,.
\]
The models used to determine $p$ and $q$ are
\[
  \Bal
    p &= p_0\beta\exp\left[-\frac{\Ve^e_v - \Ve^e_{v0}}{\kappatilde}\right] \quad \text{with} \quad
     \beta = 1 + \tfrac{3}{2}\,\frac{\alpha}{\kappatilde}\,(\Ve^e_s)^2 \\
    q &= 3\mu\Ve^e_s \,.
  \Eal
\]
The strains are updated using
\[
  \Beps^e = \Beps^e_{\rm trial} - \Delta\gamma\,\Partial{f}{\Bsig}
  \quad \text{where} \quad \Beps^e_{\rm trial} = \Beps^e_n + \Delta\Beps
     = \Beps^e_n + (\Beps - \Beps_n) \,.
\]

{\footnotesize
{\bf Remark 1:}  The interface with MPMICE, among other things in Uintah, requires the
computation of the quantity $dp/dJ$.  Since $J$ does not appear in the above equation we
proceed as explained below.
\[
  \Bal
   J & = \det(\BF) = \det(\Bone + \GradX{\Bu}) = \det(\Bone + \Beps) \\
     & = 1 + \Tr\Beps + \Half\left[(\Tr\Beps)^2 - \Tr(\Beps^2)\right] + \det(\Beps) \,.
     & = 1 + \Ve_v + \Half\left[\Ve_v^2 - \Tr(\Beps^2)\right] + \det(\Beps) \,.
  \Eal
\]
Also,
\[
   J = \frac{\rho_0}{\rho} = \frac{V}{V_0} \quad \Tand \quad
   \Ve_v = \frac{V-V_0}{V_0} = \frac{V}{V_0} - 1 = J - 1 \,.
\]
We use the relation $J = 1 + \Ve_v$ while keeping in mind that this is {\em true only for
infinitesimal strains and plastic incompressibility} for which
$\Ve_v^2$, $\Tr(\Beps^2)$, and $\det(\Beps)$ are zero.  Under these conditions
\[
   \Partial{p}{J} = \Partial{p}{\Ve_v}\,\Partial{\Ve_v}{J} = \Partial{p}{\Ve_v} \quad \Tand
   \quad
   \Partial{p}{\rho} = \Partial{p}{\Ve_v}\,\Partial{\Ve_v}{J}\,\Partial{J}{\rho}
      = -\frac{J}{\rho}\,\Partial{p}{\Ve_v} \,.
\]

{\bf Remark 2:} MPMICE also needs the density at a given pressure.  For the Borja model, with
$\Ve_v = J-1 = \rho_0/\rho -1$, we have
\[
  \rho = \rho_0\left[1 + \Ve_{v0} + \kappatilde\ln\left(\frac{p}{p_0\beta}\right)\right]^{-1}\,.
\]

{\bf Remark 3:}  The quantity $q$ is related to the deviatoric part of the Cauchy stress, $\BsT$
as follows:
\[
   q = \sqrt{3J_2} \quad \text{where} \quad J_2 = \Half\,\BsT:\BsT \,.
\]
The shear modulus relates the deviatoric stress $\BsT$ to the deviatoric strain $\BeT^e$.  We
assume a relation of the form
\[
   \BsT = 2\mu\BeT^e \,.
\]
Note that the above relation assumes a linear elastic type behavior.  Then we get the Borja
shear model:
\[
  q = \sqrt{\tfrac{3}{2}\,\BsT:\BsT} = \sqrt{\tfrac{3}{2}}\,(2\mu)\,\sqrt{\BeT^e:\BeT^e}
     = \sqrt{\tfrac{3}{2}}\,(2\mu)\,\sqrt{\tfrac{3}{2}}\,\Ve^e_s = 3\mu\Ve^e_s \,.
\]
}

\subsection{Elastic-plastic stress update}
For elasto-plasticity we start with a yield function of the form
\[
   f = \left(\frac{q}{M}\right)^2 + p(p-p_c) \le 0
   \quad \text{where} \quad
  \frac{1}{p_c}\,\Deriv{p_c}{t} = \frac{1}{\lambdatilde- \kappatilde}\,\Deriv{\Ve_v^p}{t} \,.
\]
Integrating the ODE for $p_c$ with the initial condition $p_c(t_n) = (p_c)_n$, at $t = t_{n+1}$,
\[
   (p_c)_{n+1} = (p_c)_n \exp\left[\frac{(\Ve_v^p)_{n+1} - (\Ve_v^p)_n}{\lambdatilde - \kappatilde}\right] \,.
\]
From the additive decomposition of the strain into elastic and plastic parts, and if the elastic trial
strain is defined as
\[
   (\Ve_v^e)_\Trial := (\Ve_v^e)_n + \Delta\Ve_v
\]
we have
\[
   \Ve_v^p = \Ve_v - \Ve_v^e \quad \implies \quad
   (\Ve_v^p)_{n+1} - (\Ve_v^p)_n = (\Ve_v)_{n+1} - (\Ve_v^e)_{n+1} - (\Ve_v)_{n} + (\Ve_v^e)_{n}
                               = \Delta\Ve_v + (\Ve_v^e)_{n} - (\Ve_v^e)_{n+1}
                               = (\Ve_v^e)_\Trial - (\Ve_v^e)_{n+1} \,.
\]
Therefore we can write
\[
   (p_c)_{n+1} = (p_c)_n \exp\left[\frac{(\Ve_v^e)_\Trial - (\Ve_v^e)_{n+1}}{\lambdatilde - \kappatilde}\right] \,.
\]
The flow rule is assumed to be given by
\[
   \Partial{\Beps^p}{t} = \gamma\,\Partial{f}{\Bsig} \,.
\]
Integration of the PDE with backward Euler gives
\[
  \Beps^p_{n+1} = \Beps^p_n + \Delta t\,\gamma_{n+1}\,\left[\Partial{f}{\Bsig}\right]_{n+1}
             = \Beps^p_n + \Delta\gamma\,\left[\Partial{f}{\Bsig}\right]_{n+1} \,.
\]
This equation can be expressed in terms of the trial elastic strain as follows.
\[
  \Beps_{n+1}-\Beps^e_{n+1} = \Beps_n - \Beps^e_n + \Delta\gamma\,\left[\Partial{f}{\Bsig}\right]_{n+1}
\]
or
\[
  \Beps^e_{n+1} = \Delta\Beps + \Beps^e_n - \Delta\gamma\,\left[\Partial{f}{\Bsig}\right]_{n+1}
             = \Beps^e_\Trial - \Delta\gamma\,\left[\Partial{f}{\Bsig}\right]_{n+1} \,.
\]
In terms of the volumetric and deviatoric components
\[
  (\Ve_v^e)_{n+1} = \Tr(\Beps^e_{n+1}) = \Tr(\Beps^e_\Trial) - \Delta\gamma\,\Tr\left[\Partial{f}{\Bsig}\right]_{n+1} = (\Ve_v^e)_\Trial - \Delta\gamma\,\Tr\left[\Partial{f}{\Bsig}\right]_{n+1}
\]
and
\[
  \BeT^e_{n+1} = \BeT^e_\Trial - \Delta\gamma\,\left[\left(\Partial{f}{\Bsig}\right)_{n+1}
      - \tfrac{1}{3}\,\Tr\left(\Partial{f}{\Bsig}\right)_{n+1}\Bone\right] \,.
\]
With $\BsT = \Bsig - p\Bone$, we have
\[
  \Partial{f}{\Bsig} = \Partial{f}{\BsT}:\Partial{\BsT}{\Bsig} + \Partial{f}{p}\,\Partial{p}{\Bsig}
    = \Partial{f}{\BsT}:[\SfI^{(s)} - \tfrac{1}{3}\,\Bone\otimes\Bone]
      + \Partial{f}{p}\,\Bone
    = \Partial{f}{\BsT} - \tfrac{1}{3}\,\Tr\left[\Partial{f}{\BsT}\right]\Bone
      + \Partial{f}{p}\,\Bone
\]
and
\[
  \tfrac{1}{3}\,\Tr\left[\Partial{f}{\Bsig}\right]\Bone =
    \tfrac{1}{3}\left(\Tr\left[\Partial{f}{\BsT}\right] - \Tr\left[\Partial{f}{\BsT}\right]
      + 3\Partial{f}{p}\right)\Bone  =  \Partial{f}{p}\,\Bone \,.
\]

{\footnotesize
{\bf Remark 4:}  Note that, because $\Bsig = \Bsig(p, q, p_c)$ the
chain rule should contain a contribution from $p_c$:
\[
  \Partial{f}{\Bsig} = \Partial{f}{q}\,\Partial{q}{\Bsig} + \Partial{f}{p}\,\Partial{p}{\Bsig}
                       + \Partial{f}{p_c}\,\Partial{p_c}{\Bsig} \,.
\]
However, the Borja implementation does not consider that extra term.  Also note that for the present model
\[
  \Bsig = \Bsig(p(\Ve^e_v,\Ve^e_s,\Ve^p_v, \Ve^p_s), \BsT(\Ve^e_v, \Ve^e_s, \Ve^p_v,\Ve^p_s), p_c(\Ve^p_v))
\]
}

Therefore, for situations where $\Tr(\partial f/\partial \BsT) = \Bzero$, we have
\[
  \Partial{f}{\Bsig} - \tfrac{1}{3}\,\Tr\left[\Partial{f}{\Bsig}\right]\Bone =
     \Partial{f}{\BsT} - \tfrac{1}{3}\,\Tr\left[\Partial{f}{\BsT}\right]\Bone =
     \Partial{f}{\BsT} \,.
\]
The deviatoric strain update can be written as
\[
  \BeT^e_{n+1} = \BeT^e_\Trial - \Delta\gamma\,\left(\Partial{f}{\BsT}\right)_{n+1}
\]
and the shear invariant update is
\[
  (\Ve_s^e)_{n+1} = \sqrt{\tfrac{2}{3}}\,
  \sqrt{\BeT^e_{n+1}:\BeT^e_{n+1}}
  = \sqrt{\tfrac{2}{3}}\,\sqrt{\BeT^e_\Trial:\BeT^e_\Trial
     - 2\Delta\gamma\,\left[\Partial{f}{\BsT}\right]_{n+1}:\BeT^e_\Trial
     + (\Delta\gamma)^2\left[\Partial{f}{\BsT}\right]_{n+1}:\left[\Partial{f}{\BsT}\right]_{n+1}}
\]
The derivative of $f$ can be found using the chain rule (for smooth $f$):
\[
   \Partial{f}{\Bsig} = \Partial{f}{p}\,\Partial{p}{\Bsig} + \Partial{f}{q}\,\Partial{q}{\Bsig}
     = (2p - p_c)\,\Partial{p}{\Bsig} + \frac{2q}{M^2}\,\Partial{q}{\Bsig} \,.
\]
Now, with $p = 1/3\,\Tr(\Bsig)$ and $q = \sqrt{3/2\,\Bs:\Bs}$, we have
\[
  \Bal
   \Partial{p}{\Bsig} & = \Partial{}{\Bsig}\left[\tfrac{1}{3}\,\Tr(\Bsig)\right] = \tfrac{1}{3}\,\Bone \\
   \Partial{q}{\Bsig} & = \Partial{}{\Bsig}\left[\sqrt{\tfrac{3}{2}\,\BsT:\BsT}\right]
     = \sqrt{\tfrac{3}{2}}\,\frac{1}{\sqrt{\BsT:\BsT}}\,\Partial{\BsT}{\Bsig}:\BsT
     = \sqrt{\tfrac{3}{2}}\,\frac{1}{\Norm{\BsT}{}}\,\left[\SfI^{(s)}-\tfrac{1}{3}\Bone\otimes\Bone\right]:\BsT
     = \sqrt{\tfrac{3}{2}}\,\frac{\BsT}{\Norm{\BsT}{}}\,.
  \Eal
\]
Therefore,
\[
   \Partial{f}{\Bsig} = \frac{2p - p_c}{3}\,\Bone + \sqrt{\tfrac{3}{2}}\,\frac{2q}{M^2}\,\frac{\BsT}{\Norm{\BsT}{}} \,.
\]
Recall that
\[
   \Bsig = p\,\Bone + \sqrt{\tfrac{2}{3}}\, q\, \BnT = p\,\Bone + \BsT \,.
\]
Therefore,
\[
   \BsT = \sqrt{\tfrac{2}{3}}\,q\,\BnT
   \quad \Tand \quad
   \Norm{\BsT}{} = \sqrt{\BsT:\BsT} = \sqrt{\tfrac{2}{3}\,q^2\,\BnT:\BnT} =
     \sqrt{\tfrac{2}{3}\,q^2\,\frac{\BeT^e:\BeT^e}{\Norm{\BeT^e}{}^2}}
     = \sqrt{\tfrac{2}{3}\,q^2} = \sqrt{\tfrac{2}{3}}\,q \,.
\]
So we can write
\Beq
   \Partial{f}{\Bsig} = \frac{2p - p_c}{3}\,\Bone + \sqrt{\tfrac{3}{2}}\,\frac{2q}{M^2}\,\BnT \,.
\Eeq
Using the above relation we have
\[
   \Partial{f}{p} = \tfrac{1}{3}\,\Tr\left[\Partial{f}{\Bsig}\right] = 2p-p_c
   \quad \Tand \quad
   \Partial{f}{\BsT}  = \Partial{f}{\Bsig} - \Partial{f}{p}\Bone
                      = \sqrt{\tfrac{3}{2}}\,\frac{2q}{M^2}\,\BnT \,.
\]
The strain updates can now be written as
\[
  \Bal
  (\Ve_v^e)_{n+1} & =  (\Ve_v^e)_\Trial - \Delta\gamma\,[2p_{n+1} - (p_c)_{n+1}] \\
  \BeT^e_{n+1} & = \BeT^e_\Trial - \sqrt{\tfrac{3}{2}}\,\Delta\gamma\,\left(\frac{2q_{n+1}}{M^2_{n+1}}\right)
           \BnT_{n+1}  \\
  (\Ve_s^e)_{n+1} & =
    \sqrt{\tfrac{2}{3}}\,\sqrt{\BeT^e_\Trial:\BeT^e_\Trial
     - \sqrt{6}\,(\Delta\gamma)^2\left(\frac{2q_{n+1}}{M^2_{n+1}}\right)\BnT_{n+1}:\BeT^e_\Trial
     + \tfrac{3}{2}\,(\Delta\gamma)^4\,\left(\frac{2q_{n+1}}{M^2_{n+1}}\right)^2 } \,.
  \Eal
\]
From the second equation above,
\[
  \BnT_{n+1}:\BeT^e_\Trial =
   \BnT_{n+1}:\BeT^e_{n+1} + \sqrt{\tfrac{3}{2}}\,\Delta\gamma\,\left(\frac{2q_{n+1}}{M^2_{n+1}}\right)
           \BnT_{n+1}:\BnT_{n+1} =
   \frac{\BeT^e_{n+1}:\BeT^e_{n+1}}{\Norm{\BeT^e_{n+1}}{}} +
      \sqrt{\tfrac{3}{2}}\,\Delta\gamma\,\left(\frac{2q_{n+1}}{M^2_{n+1}}\right) =
   \Norm{\BeT^e_{n+1}}{} +
      \sqrt{\tfrac{3}{2}}\,\Delta\gamma\,\left(\frac{2q_{n+1}}{M^2_{n+1}}\right) \,.
\]
Also notice that
\[
  \BeT^e_\Trial:\BeT^e_\Trial = \BeT^e_{n+1}:\BeT^e_{n+1} + 2\,\sqrt{\tfrac{3}{2}}\,\Delta\gamma\,
     \left(\frac{2q_{n+1}}{M^2_{n+1}}\right)\BeT^e_{n+1}:\BnT_{n+1} +
     \left[\sqrt{\tfrac{3}{2}}\,\Delta\gamma\,\left(\frac{2q_{n+1}}{M^2_{n+1}}\right)\right]^2
\]
or,
\[
  \Norm{\BeT^e_\Trial}{}^2 = \left[\Norm{\BeT^e_{n+1}}{} + \sqrt{\tfrac{3}{2}}\,\Delta\gamma\,\left(\frac{2q_{n+1}}{M^2_{n+1}}\right)\right]^2 \,.
\]
Therefore,
\[
  \BnT_{n+1}:\BeT^e_\Trial = \Norm{\BeT^e_\Trial}{}
\]
and we have
\[
  (\Ve_s^e)_{n+1} =
    \sqrt{\tfrac{2}{3}}\,\sqrt{\Norm{\BeT^e_\Trial}{}^2
     - \sqrt{6}\,(\Delta\gamma)^2\left(\frac{2q_{n+1}}{M^2_{n+1}}\right)\Norm{\BeT^e_\Trial}{}
     + \tfrac{3}{2}\,(\Delta\gamma)^4\,\left(\frac{2q_{n+1}}{M^2_{n+1}}\right)^2 }
    = \sqrt{\tfrac{2}{3}}\,\Norm{\BeT^e_\Trial}{} - \Delta\gamma\,\left(\frac{2q_{n+1}}{M^2_{n+1}}\right) \,.
\]
The elastic strain can therefore be updated using
\[
  \Bal
    (\Ve_v^e)_{n+1} & =  (\Ve_v^e)_\Trial - \Delta\gamma\,[2p_{n+1} - (p_c)_{n+1}] \\
    (\Ve_s^e)_{n+1} & =  (\Ve_s^e)_\Trial - \Delta\gamma\,\left(\frac{2q_{n+1}}{M^2_{n+1}}\right) \,.
  \Eal
\]
The consistency condition is needed to close the above equations
\[
   f = \left(\frac{q_{n+1}}{M}\right)^2 + p_{n+1}[p_{n+1}-(p_c)_{n+1}] = 0  \,.
\]
The unknowns are $(\Ve_v^e)_{n+1}$, $(\Ve_s^e)_{n+1}$ and $\Delta\gamma$.  Note that we can express
the three equations as
\Beq
  \Bal
    (\Ve_v^e)_{n+1} & =  (\Ve_v^e)_\Trial - \Delta\gamma\,\left[\Partial{f}{p}\right]_{n+1} \\
    (\Ve_s^e)_{n+1} & =  (\Ve_s^e)_\Trial - \Delta\gamma\,\left[\Partial{f}{q}\right]_{n+1} \\
    f_{n+1} & = 0 \,.
  \Eal
\Eeq

\subsection{Newton iterations}
The three nonlinear equations in the three unknowns can be solved using Newton iterations
for smooth yield functions.  Let us define the residual as
\[
   \Mr(\Mx) = \begin{bmatrix}
    (\Ve_v^e)_{n+1} -  (\Ve_v^e)_\Trial + \Delta\gamma\,\left[\Partial{f}{p}\right]_{n+1} \\
    (\Ve_s^e)_{n+1} -  (\Ve_s^e)_\Trial + \Delta\gamma\,\left[\Partial{f}{q}\right]_{n+1} \\
    f_{n+1} \end{bmatrix} =: \begin{bmatrix} r_1 \\ r_2 \\ r_3 \end{bmatrix}
   \quad \text{where} \quad
   \Mx = \begin{bmatrix} (\Ve_v^e)_{n+1} \\ (\Ve_s^e)_{n+1} \\ f_{n+1} \end{bmatrix}
        =: \begin{bmatrix} x_1 \\ x_2 \\ x_3 \end{bmatrix} \,.
\]
The Newton root finding algorithm is :
\begin{algorithm}
  \begin{algorithmic}
    \REQUIRE $\Mx^0$
    \STATE $k \leftarrow 0$
    \WHILE {$\Mr(\Mx^k) \ne 0$}
      \STATE $\Mx^{k+1} \Leftarrow \Mx^k - \left[\left(\Partial{\Mr}{\Mx}\right)^{-1}\right]_{\Mx^k}\cdot
              \Mr(\Mx^k)$
      \STATE $k \leftarrow k+1$
    \ENDWHILE
  \end{algorithmic}
\end{algorithm}

To code the algorithm we have to find the derivatives of the residual with respect to the primary variables.
Let's do the terms one by one.  For the first row,
\[
  \Bal
  \Partial{r_1}{x_1} & = \Partial{}{\Ve_v^e}\left[\Ve_v^e -  (\Ve_v^e)_\Trial + \Delta\gamma\,(2p-p_c)\right]
     = 1 + \Delta\gamma\left(2\Partial{p}{\Ve_v^e} - \Partial{p_c}{\Ve_v^e}\right) \\
  \Partial{r_1}{x_2} & = \Partial{}{\Ve_s^e}\left[\Ve_v^e -  (\Ve_v^e)_\Trial + \Delta\gamma\,(2p-p_c)\right]
     = 2\Delta\gamma\,\Partial{p}{\Ve_s^e}\\
  \Partial{r_1}{x_3} & = \Partial{}{\Delta\gamma}\left[\Ve_v^e -  (\Ve_v^e)_\Trial + \Delta\gamma\,(2p-p_c)\right]
     = 2p - p_c = \Partial{f}{p}
  \Eal
\]
where
\[
  \Bal
   \Partial{p}{\Ve_v^e} & = -\frac{p_0\,\beta}{\kappatilde}\,\exp\left[-\frac{\Ve_v^e - \Ve_{v0}^e}{\kappatilde}\right] = \frac{p}{\kappatilde} \quad, \quad
   \Partial{p_c}{\Ve_v^e} = \frac{(p_c)_n}{\kappatilde-\lambdatilde}\,\exp\left[\frac{\Ve_v^e - (\Ve_{v}^e)_\Trial}{\kappatilde-\lambdatilde}\right] \quad \Tand \\
   \Partial{p}{\Ve_s^e} & = \frac{3\,p_0\,\alpha\,\Ve_s^e}{\kappatilde}\,\exp\left[-\frac{\Ve_v^e - \Ve_{v0}^e}{\kappatilde}\right] \,.
  \Eal
\]
For the second row,
\[
  \Bal
  \Partial{r_2}{x_1} & = \Partial{}{\Ve_v^e}\left[\Ve_s^e -  (\Ve_s^e)_\Trial + \Delta\gamma\,\frac{2q}{M^2}\right]
     = \frac{2\Delta\gamma}{M^2}\,\Partial{q}{\Ve_v^e} \\
  \Partial{r_2}{x_2} & = \Partial{}{\Ve_s^e}\left[\Ve_s^e -  (\Ve_s^e)_\Trial + \Delta\gamma\,\frac{2q}{M^2}\right]
     = 1 + \frac{2\Delta\gamma}{M^2}\,\Partial{q}{\Ve_s^e}\\
  \Partial{r_2}{x_3} & = \Partial{}{\Delta\gamma}\left[\Ve_s^e -  (\Ve_s^e)_\Trial + \Delta\gamma\,\frac{2q}{M^2}\right]
     = \frac{2q}{M^2} = \Partial{f}{q}
  \Eal
\]
where
\[
  \Partial{q}{\Ve_v^e} = -\frac{3p_0\,\alpha\,\Ve_s^e}{\kappatilde}\,\exp\left[-\frac{\Ve_v^e - \Ve_{v0}^e}{\kappatilde}\right] = \Partial{p}{\Ve_s^e}
  \quad \Tand \quad
  \Partial{q}{\Ve_s^e} = 3\mu_0 + 3p_0\,\alpha\,\exp\left[-\frac{\Ve_v^e - \Ve_{v0}^e}{\kappatilde}\right] = 3\mu \,.
\]
For the third row,
\[
  \Bal
  \Partial{r_3}{x_1} & = \Partial{}{\Ve_v^e}\left[\frac{q^2}{M^2} + p\,(p - p_c)\right]
     = \frac{2q}{M^2}\,\Partial{q}{\Ve_v^e} + (2p - p_c)\,\Partial{p}{\Ve_v^e} - p\,\Partial{p_c}{\Ve_v^e}
     = \Partial{f}{q}\,\Partial{q}{\Ve_v^e} + \Partial{f}{p}\,\Partial{p}{\Ve_v^e} - p\,\Partial{p_c}{\Ve_v^e} \\
  \Partial{r_3}{x_2} & = \Partial{}{\Ve_s^e}\left[\frac{q^2}{M^2} + p\,(p - p_c)\right]
     = \frac{2q}{M^2}\,\Partial{q}{\Ve_s^e} + (2p - p_c)\,\Partial{p}{\Ve_s^e}
     = \Partial{f}{q}\,\Partial{q}{\Ve_s^e} + \Partial{f}{p}\,\Partial{p}{\Ve_s^e} \\
  \Partial{r_3}{x_3} & = \Partial{}{\Delta\gamma}\left[\frac{q^2}{M^2} + p\,(p - p_c)\right]
     =  0 \,.
  \Eal
\]
We have to invert a matrix in the Newton iteration process.  Let us see whether we can make this
quicker to do.  The Jacobian matrix has the form
\[
  \Partial{\Mr}{\Mx} = \begin{bmatrix}\Partial{r_1}{x_1} & \Partial{r_1}{x_2} & \Partial{r_1}{x_3} \\
     \Partial{r_2}{x_1} & \Partial{r_2}{x_2} & \Partial{r_2}{x_3} \\
     \Partial{r_3}{x_1} & \Partial{r_3}{x_2} & \Partial{r_3}{x_3} \end{bmatrix}
     = \begin{bmatrix} \MAmat & \MBmat \\ \MCmat & 0 \end{bmatrix}
\]
where
\[
  \MAmat = \begin{bmatrix}\Partial{r_1}{x_1} & \Partial{r_1}{x_2} \\
                       \Partial{r_2}{x_1} & \Partial{r_2}{x_2} \end{bmatrix} \,,\quad
  \MBmat = \begin{bmatrix}\Partial{r_1}{x_3} \\ \Partial{r_2}{x_3} \end{bmatrix} \,,\quad \Tand \quad
  \MCmat = \begin{bmatrix}\Partial{r_3}{x_1} & \Partial{r_3}{x_2} \end{bmatrix} \,.
\]
We can also break up the $\Mx$ and $\Mr$ matrices:
\[
  \Delta\Mx = \Mx^{k+1}-\Mx^k = \begin{bmatrix} \Delta\Mx^{vs} \\ \Delta x_3 \end{bmatrix} \,, \quad
  \Mr = \begin{bmatrix} \Mr^{vs} \\ r_3 \end{bmatrix}
  \quad \text{where} \quad \Mr^{vs} = \begin{bmatrix} r_1 \\ r_2 \end{bmatrix}
   \quad \Tand \quad \Delta\Mx^{vs} = \begin{bmatrix}\Delta x_1 \\\Delta x_2 \end{bmatrix}  \,.
\]
Then
\[
  \begin{bmatrix} \Delta\Mx^{vs} \\ \Delta x_3 \end{bmatrix}
   = - \begin{bmatrix} \MAmat & \MBmat \\ \MCmat & 0 \end{bmatrix}^{-1}
                    \begin{bmatrix} \Mr^{vs} \\ r_3 \end{bmatrix}
  \quad \implies \quad
   \begin{bmatrix} \MAmat & \MBmat \\ \MCmat & 0 \end{bmatrix}
  \begin{bmatrix} \Delta\Mx^{vs} \\ \Delta x_3 \end{bmatrix}  =
                    -\begin{bmatrix} \Mr^{vs} \\ r_3 \end{bmatrix}
\]
or
\[
   \MAmat\,\Delta\Mx^{vs} + \MBmat\,\Delta x_3 = -\Mr^{vs} \quad \Tand \quad
   \MCmat\,\Delta\Mx^{vs} = -r_3 \,.
\]
From the first equation above,
\[
  \Delta\Mx^{vs} = -\MAmat^{-1}\,\Mr^{vs} - \MAmat^{-1}\,\MBmat\,\Delta x_3 \,.
\]
Plugging in the second equation gives
\[
   r_3 = \MCmat\,\MAmat^{-1}\,\Mr^{vs} + \MCmat\,\MAmat^{-1}\,\MBmat\,\Delta x_3 \,.
\]
Rearranging,
\[
  \Delta x_3 = x_3^{k+1} - x_3^k = \frac{-\MCmat\,\MAmat^{-1}\,\Mr^{vs} + r_3}{\MCmat\,\MAmat^{-1}\,\MBmat} \,.
\]
Using the above result,
\[
  \Delta\Mx^{vs} = -\MAmat^{-1}\,\Mr^{vs} - \MAmat^{-1}\,\MBmat\,\left(\frac{-\MCmat\,\MAmat^{-1}\,\Mr^{vs} + r_3}{\MCmat\,\MAmat^{-1}\,\MBmat}\right) \,.
\]
We therefore have to invert only a $2 \times 2 $ matrix.

\subsection{Tangent calculation: elastic}
We want to find the derivative of the stress with respect to the strain:
\Beq
   \Partial{\Bsig}{\Beps} = \Bone\otimes\Partial{p}{\Beps} +
      \sqrt{\tfrac{2}{3}}\,\BnT\otimes\Partial{q}{\Beps} +
      \sqrt{\tfrac{2}{3}}\,q\,\Partial{\BnT}{\Beps}  \,.
\Eeq
For the first term above,
\[
   \Partial{p}{\Beps} = p_0\,\exp\left[-\frac{\Ve^e_v - \Ve^e_{v0}}{\kappatilde}\right]\Partial{\beta}{\Beps}
      - p_0\,\frac{\beta}{\kappatilde}\,
        \exp\left[-\frac{\Ve^e_v - \Ve^e_{v0}}{\kappatilde}\right]\Partial{\Ve^e_v}{\Beps}
     = p_0\,\exp\left[-\frac{\Ve^e_v - \Ve^e_{v0}}{\kappatilde}\right]\left(\Partial{\beta}{\Beps} -
            \frac{\beta}{\kappatilde}\,\Partial{\Ve^e_v}{\Beps} \right) \,.
\]
Now,
\[
   \Partial{\beta}{\Beps} = \frac{3\alpha}{\kappatilde}\,\Ve^e_s\,\Partial{\Ve^e_s}{\Beps} \,.
\]
Therefore,
\[
  \Partial{p}{\Beps} = \frac{p_0}{\kappatilde}\,
      \exp\left[-\frac{\Ve^e_v - \Ve^e_{v0}}{\kappatilde}\right]\left(3\alpha\,\Ve^e_s\Partial{\Ve^e_s}{\Beps} -
            \beta\,\Partial{\Ve^e_v}{\Beps} \right) \,.
\]
We now have to figure out the other derivatives in the above expression.  First,
\[
  \Partial{\Ve^e_s}{\Beps} = \sqrt{\tfrac{2}{3}}\,\frac{1}{\sqrt{\BeT^e:\BeT^e}}\,\Partial{\BeT^e}{\Beps}:\BeT^e =
     \sqrt{\tfrac{2}{3}}\,\frac{1}{\Norm{\BeT^e}{}}\,
     \left(\Partial{\Beps^e}{\Beps} - \tfrac{1}{3}\Bone\otimes\Partial{\Ve^e_v}{\Beps} \right):\BeT^e\,.
\]
For the special situation where all the strain is elastic, $\Beps = \Beps^e$, and (see Wikipedia
article on tensor derivatives)
\[
  \Partial{\Beps^e}{\Beps} = \Partial{\Beps}{\Beps} = \SfI^{(s)} \quad \Tand \quad
  \Partial{\Ve^e_v}{\Beps} = \Partial{\Ve_v}{\Beps} = \Bone \,.
\]
That gives us
\[
  \Partial{\Ve^e_s}{\Beps} = \sqrt{\tfrac{2}{3}}\,\frac{1}{\Norm{\BeT^e}{}}\,
     \left(\SfI^{(s)} - \tfrac{1}{3}\Bone\otimes\Bone \right):\BeT^e
   = \sqrt{\tfrac{2}{3}}\,\frac{1}{\Norm{\BeT^e}{}}\,
     \left[\BeT^e - \tfrac{1}{3}\Tr(\BeT^e)\Bone\right] \,.
\]
But $\Tr(\BeT^e)=0$ because this is the deviatoric part of the strain and we have
\[
  \boxed{
  \Partial{\Ve^e_s}{\Beps} = \sqrt{\tfrac{2}{3}}\,\frac{\BeT^e}{\Norm{\BeT^e}{}} = \sqrt{\tfrac{2}{3}}\,\BnT
  }
  \quad \Tand \quad
  \boxed{
  \Partial{\Ve^e_v}{\Beps} = \Bone \,.
  }
\]
Using these, we get
\Beq
  \Partial{p}{\Beps} = \frac{p_0}{\kappatilde}\,
      \exp\left[-\frac{\Ve^e_v - \Ve^e_{v0}}{\kappatilde}\right]\left(\sqrt{6}\,\alpha\,\Ve^e_s\,\BnT -
            \beta\,\Bone \right) \,.
\Eeq
The derivative of $q$ with respect to $\Beps$ can be calculated in a similar way, i.e.,
\[
  \Partial{q}{\Beps} = 3\mu\,\Partial{\Ve^e_s}{\Beps} + 3\Ve^e_s\,\Partial{\mu}{\Beps}
   = 3\mu\,\Partial{\Ve^e_s}{\Beps} - 3\frac{p_0}{\kappatilde}\,\alpha\,\Ve^e_s\,
      \exp\left[-\frac{\Ve^e_v - \Ve^e_{v0}}{\kappatilde}\right]\,\Partial{\Ve^e_v}{\Beps} \,.
\]
Using the expressions in the boxes above,
\Beq
  \Partial{q}{\Beps} = \sqrt{6}\,\mu\,\BnT - 3\frac{p_0}{\kappatilde}\,
      \exp\left[-\frac{\Ve^e_v - \Ve^e_{v0}}{\kappatilde}\right]\,\alpha\,\Ve^e_s\,\Bone \,.
\Eeq
Also,
\[
   \Partial{\BnT}{\Beps} = \sqrt{\tfrac{2}{3}}\,\left[\frac{1}{\Ve^e_s}\,\Partial{\BeT^e}{\Beps}
     - \frac{1}{(\Ve^e_s)^2}\,\BeT^e\otimes\Partial{\Ve^e_s}{\Beps}\right] \,.
\]
Using the previously derived expression, we have
\[
   \Partial{\BnT}{\Beps} = \sqrt{\tfrac{2}{3}}\,\frac{1}{\Ve^e_s}\,\left[
        \SfI^{(s)} - \tfrac{1}{3}\,\Bone\otimes\Bone
     - \sqrt{\tfrac{2}{3}}\,\frac{1}{\Ve^e_s}\,\frac{\BeT^e\otimes\BeT^e}{\Norm{\BeT^e}{}}\right]
\]
or
\Beq
   \Partial{\BnT}{\Beps} = \sqrt{\tfrac{2}{3}}\,\frac{1}{\Ve^e_s}\,\left[
        \SfI^{(s)} - \tfrac{1}{3}\,\Bone\otimes\Bone - \BnT\otimes\BnT\right] \,.
\Eeq
Plugging the expressions for these derivatives in the original equation, we get
\[
  \Bal
   \Partial{\Bsig}{\Beps} & = \frac{p_0}{\kappatilde}\,
      \exp\left[-\frac{\Ve^e_v - \Ve^e_{v0}}{\kappatilde}\right]
      \left(\sqrt{6}\,\alpha\,\Ve^e_s\,\Bone\otimes\BnT - \beta\,\Bone\otimes\Bone \right) +
      2\mu\,\BnT\otimes\BnT - \sqrt{6}\frac{p_0}{\kappatilde}\,
      \exp\left[-\frac{\Ve^e_v - \Ve^e_{v0}}{\kappatilde}\right]\,\alpha\,\Ve^e_s\,\BnT\otimes\Bone +\\
      & \qquad \qquad \tfrac{2}{3}\,\frac{q}{\Ve^e_s}\,\left[
        \SfI^{(s)} - \tfrac{1}{3}\,\Bone\otimes\Bone - \BnT\otimes\BnT\right] \,.
  \Eal
\]
Reorganizing,
\Beq
  \boxed{
  \Bal
   \Partial{\Bsig}{\Beps} & = \frac{\sqrt{6}\,p_0\,\alpha\,\Ve^e_s}{\kappatilde}\,
      \exp\left[-\frac{\Ve^e_v - \Ve^e_{v0}}{\kappatilde}\right](\Bone\otimes\Bn + \Bn\otimes\Bone) -
      \left(\frac{p_0\beta}{\kappatilde}\, \exp\left[-\frac{\Ve^e_v - \Ve^e_{v0}}{\kappatilde}\right]
       +\tfrac{2}{9}\,\frac{q}{\Ve_s^e}\right) \Bone\otimes\Bone + \\
     & \qquad \qquad 2\left(\mu - \tfrac{1}{3}\,\frac{q}{\Ve^e_s}\right)\,\BnT\otimes\BnT
           + \tfrac{2}{3}\,\frac{q}{\Ve^e_s}\,\SfI^{(s)}\,.
  \Eal
  }
\Eeq

\subsection{Tangent calculation: elastic-plastic}
From the previous section recall that
\[
   \Partial{\Bsig}{\Beps} = \Bone\otimes\Partial{p}{\Beps} +
      \sqrt{\tfrac{2}{3}}\,\BnT\otimes\Partial{q}{\Beps} +
      \sqrt{\tfrac{2}{3}}\,q\,\Partial{\BnT}{\Beps}
\]
where
\[
  \Bal
  \Partial{p}{\Beps} & = \frac{p_0}{\kappatilde}\,
      \exp\left[-\frac{\Ve^e_v - \Ve^e_{v0}}{\kappatilde}\right]\left(3\alpha\,\Ve^e_s\Partial{\Ve^e_s}{\Beps} -
            \beta\,\Partial{\Ve^e_v}{\Beps} \right) \,,\qquad
  \Partial{q}{\Beps}  = 3\mu\,\Partial{\Ve^e_s}{\Beps} - 3\frac{p_0}{\kappatilde}\,\alpha\,\Ve^e_s \,
      \exp\left[-\frac{\Ve^e_v - \Ve^e_{v0}}{\kappatilde}\right]\,\Partial{\Ve^e_v}{\Beps} \quad \Tand \\
   \Partial{\BnT}{\Beps} & = \sqrt{\tfrac{2}{3}}\,\left[\frac{1}{\Ve^e_s}\,\Partial{\BeT^e}{\Beps}
     - \frac{1}{(\Ve^e_s)^2}\,\BeT^e\otimes\Partial{\Ve^e_s}{\Beps}\right] \,.
  \Eal
\]
The total strain is equal to the elastic strain for the purely elastic case and the tangent is relatively
straightforward to calculate.  For the elastic-plastic case we have
\[
   \Beps^e_{n+1} = \Beps^e_\Trial - \Delta\gamma\left[\Partial{f}{\Bsig}\right]_{n+1} \,.
\]
Dropping the subscript $n+1$ for convenience, we have
\[
   \Partial{\Beps^e}{\Beps} = \Partial{\Beps^e_\Trial}{\Beps}
     - \Partial{f}{\Bsig}\otimes\Partial{\Delta\gamma}{\Beps}
     - \Delta\gamma\,\Partial{}{\Beps}\left[\Partial{f}{\Bsig}\right]
     = \SfI^{(s)}
     - \left[\frac{2p-p_c}{3}\,\Bone + \sqrt{\tfrac{3}{2}}\,\frac{2q}{M^2}\,\BnT\right]
       \otimes\Partial{\Delta\gamma}{\Beps}
     - \Delta\gamma\,\Partial{}{\Beps}
     \left[\frac{2p-p_c}{3}\,\Bone + \sqrt{\tfrac{3}{2}}\,\frac{2q}{M^2}\,\BnT\right] \,.
\]

%\begin{figure}[htb!]
%  \centering
%  %\includegraphics[width=0.4\linewidth]{./FIGS/SimpleBurnWithoutPressCC.png}
%  %\includegraphics[width=0.4\linewidth]{./FIGS/SimpleBurnWithPressCC.png}
%  \caption{Simulation of an explosion in a half space overlaid by a thin layer with a
%           simple burn model and compressible neo-Hookean behavior.  There is no apparent
%           fast moving shock wave in the material because the speed of sound in the half space
%           is low.  Movies of this simulation can be found in the Dropbox folder
%           SoilWithLayerSimpleBurn2D.}
%  \label{fig:SimpleBurn}
%\end{figure}

\end{document}


\section{Experimental results}
In this latter analysis, we did not care about the validation of the model: the company's experience guaranteed the correctness of the model itself. On the contrary, our goal was to study how the result of the previous model affected the final measure of the diameter, and how the same is influenced by the position of the three points on the wheel. \\

The main problem encountered in this set of tests, was due to the lack of availability of a complete \acs{WPMS} to perform acquisitions of real rolling points of the \textit{DIMA}. The only system we could use was one under development, and incomplete. Furthermore, it was also bad calibrated, so the performed measures of the diameter was more or less $40 \, mm$ bigger than the nominal size of the target. Thus, was impossible for us to make any comparison with real data.

Despite that, \textsc{Matlab} allowed us to simulate a plausible scenario, in which three laser was involved, and the rolling points was obtained as the intersection between the laser line and a circumference comparable with the wheel. In Figure \ref{fig:diam:virtual} is shown an example of a simulation. In tests described bellow, we tried to generate real scenario to determine points that could be comparable with sets of real data.
  \begin{figure}[t!]
    \centering
    \includegraphics[width=0.75\textwidth]{./images/diameter/virtual.jpg}
    \caption{Example of the simulation used to detect the three rolling points to estimate the diameter of the wheel. The black dotted lines are the rail, while the coloured ones are the laser beams.}
    \label{fig:diam:virtual}
  \end{figure}

\subsection{Effects of points' positions} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The first experiments was focus on study the variation of the error with respect to the location of the reference points in the circle. To do that, we analysed two different type of situations:
  \begin{itemize}
    \item in the first one, we moved the wheel in a reasonable range, maintaining the configuration of the acquisition system fixed;
    \item in the second one, we change the positions of the projectors one by one, keeping the others fixed, in order to look for some relations of interest between the configuration of the system and the computed error.
  \end{itemize}

In Figure \ref{fig:diam:dists} we reported the distribution of the errors, obtained with three different setups, moving the wheel along the virtual rail. The first thing we can see, is that these distributions were not linear. Thinking a while, it is easy to understand why: the motion of the points of a circumference, that moves with pure round motion, is a cycloid. So, the relationship between two points determined by the same laser at different times, will have to take into account this quadratic trend. Furthermore, we have to consider that the first order derivative of the Equation \ref{eq:diam:erone} is characterized by the presence of several sine and cosine factors, which prohibit linear distributions. \\
By improving our analysis, we have tried to determine what conditions reduce the final error, and which ones increase it. Initially, we decided to focus on the Distribution \ref{fig:diam:dists1}, because of the presence of a (maybe global) minimum. In Figure \ref{fig:diam:scenarios} we shown the best and the worst scenarios, accordingly with the error. Concerning the worst case, we can notice that a two points was very close to each other, while the third one is far with respect to the others. Looking at all the motion of the wheel, we observed that the error increased as the two points approached. Opposite considerations can be made in the best case: the error decreases as the reciprocal points distance increases. All these consideration suggested us that probably the error was minimum when the points are equally distributed along an arc. Same considerations was reached analysing the scenarios for Distributions \ref{fig:diam:dists2} and \ref{fig:diam:dists3}. Unfortunately, the collected data did not help us. All the attempts made to find a mathematical relation between the location of the points, and the error, failed. \\

Thus, we changed our approach. The great number of parameters we had to consider (the angles of the lasers, their distances from the origin of the reference system, and the length of the $y_i$ vectors) suggested us to simplify the problem. So, we decided to change only one parameter per times, and try to determine the effect of the variation in the final result. Because of the lengths of the vectors $y_i$ strictly depend by the angles $\theta_i$ and by the offsets $H_i$, we decided to ignore them and to focus only in the last parameters. In Figure \ref{fig:diam:hs} we reported the graphical results obtained moving one projector with respect to the others. In this case, we can see how the error decreases increasing the distances between the projectors: differently from the previous scenarios, this is due to the increasing in the length of the arc involved by the three points. However, as we can see from the Figure \ref{fig:diam:hs} (bottom)  the matter is not that simple. It seems that the distribution could be a discontinuous function. The only thing that, in our opinion, may had influence the result, is the angle of the projector with respect of the rail (that is $90\degree$). Many attempt was made to understand how the angle influences the error, but no
  \clearpage
  \begin{figure}[t!]
    \centering
    \begin{minipage}[c]{0.9\textwidth}
      \centering
      \includegraphics[width=\textwidth]{./images/diameter/distrib1.jpg}
      \subcaption{Distribution \#1}
      \label{fig:diam:dists1}
    \end{minipage}
    \vfill
    \begin{minipage}[c]{0.9\textwidth}
      \centering
      \includegraphics[width=\textwidth]{./images/diameter/distrib2.jpg}
      \subcaption{Distribution \#2}
      \label{fig:diam:dists2}
    \end{minipage}
    \vfill
    \begin{minipage}[c]{0.9\textwidth}
      \centering
      \includegraphics[width=\textwidth]{./images/diameter/distrib3.jpg}
      \subcaption{Distribution \#3}
      \label{fig:diam:dists3}
    \end{minipage}

    \caption{Examples of distributions of the final error varying the position of the wheel with respect to the systems.}
    \label{fig:diam:dists}
  \end{figure}
\clearpage %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \begin{figure}[t!]
    \centering
    \begin{minipage}[c]{\textwidth}
      \centering
      \includegraphics[width=\textwidth]{./images/diameter/c1_better.jpg}
    \end{minipage}
    \vfill
    \begin{minipage}[c]{\textwidth}
      \centering
      \includegraphics[width=\textwidth]{./images/diameter/c1_worst.jpg}
    \end{minipage}

    \caption{Better (on the top) and worst (on the bottom) scenarios, accordingly with the error distribution.}
    \label{fig:diam:scenarios}
  \end{figure}
\clearpage %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  \begin{figure}[t!]
    \centering
    \begin{minipage}[c]{0.9\textwidth}
      \centering
      \includegraphics[width=\textwidth]{./images/diameter/H1_1.jpg}
    \end{minipage}
    \vfill
    \begin{minipage}[c]{0.9\textwidth}
      \centering
      \includegraphics[width=\textwidth]{./images/diameter/H2_1.jpg}
    \end{minipage}

    \caption{Error distributions as the position of the first laser projector (top) and the second (bottom).}
    \label{fig:diam:hs}
  \end{figure}
  \input{./src/chapters/ch6-Diameter/tab.tex}
\clearpage
\noindent
remarkable result was found. \\

To conclude this first part of the analysis, we can say that an at least quadratic relation exists between the error made using Erone's formula and the reciprocal distances between the points involved by the measure. Nevertheless, the number of factors that influenced this measures, is big enough to make tricky the definition of a mathematical relation among the involved components. From our point of view, this could be modelled as a linear programming minimum search problem. \\

As we can realize from the analysis above, we were not interested in the numerical results, but only in the distribution of the error over the position of the points. In fact, in the case of study we knew the performance of the model in real scenarios. However, the results in our possession did not take into account the error due to $y_i$'s estimates. So we performed a last set of test to introduce this last factor.

\subsection{Error propagation} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
To conclude our analysis on this last part of the model, we correctly set al the parameters with typical values, that we had seen work properly for our systems. The empirical data that we initially used to study the problems, the \textit{bad calibrated ones}, where obtained using a device like the one described in Section \ref{sec:exp2}, so the values used for estimate $\sigma_{y_i}$ was the ones shown in Table \ref{tab:exp2:refereces}.
As we said in the previous subsection, we didn't find a useful relation between the error and the input parameters, so they are too much to synthesize the results in a simple table. Furthermore, as we shown in the figures above, there wasn't a distribution for witch the data could take sense. In Table \ref{tab:diam:tab1} we reported an example of data, collected keeping fix the system, and moving the wheel along the rails. In this case, as well as in the others, we noticed that the $\sigma_{y_i}$ did not heavily affect the final error of the measure, which always remains within the range $\left(0.1, \, 1.0\right) \, mm$. The cases where the error became greater, were in limit working condition for the system, such with the wheel over the projector. The $Y_i$ columns are the lengths of the simulated $y_i$ vectors, while the $L_i$ columns are the lengths of the sides of the triangle inscribed in the circumference; $P$ and $A$ are the perimeter and the area, respectively. Furthermore, we preferred not to return the diameter of the wheel, because the wheel being simulated, and this value was always perfectly accurate.

%


\subsection{Numerics}

From a numerical point of view, it is convenient to solve for the
eigenmodes of the linear operator $\hat q$ and $\hat a_\pm = \hat a
/2 \pm \omega_l \hat d /(2i)$.
%
We thus consider the following modified governing equations
\begin{eqnarray}
\bigl( \p_t  + \fdiss(\kk) \bigl) \hat q
&=& \hat N_q  ,\label{eqqnum} \\
\bigl( \p_t  + \fdiss(\kk) \pm  i \omega_l \bigl)  \hat a_\pm
&=& \hat N_{\pm} + \hat f_{\pm}, \label{eqapmnum}
\end{eqnarray}
where $\hat f_{\pm}$ are forcing terms and %
$\hat N_q$ and %
$\hat N_\pm = \hat N_a /2 \pm \omega_l \hat N_d/(2i)$ %
are non-linear terms computed from %
$\hat \NN_\uu = - \zeta \eez \wedge \uu - \bnabla |\uu|^2/2$ and %
$\hat N_\eta = - \bnabla \cdot (\eta \uu)$.
%
We have removed the Newtonian viscous operator in (\ref{eq_uu}) and
added more general dissipative operators in (\ref{eq_uu}) and
(\ref{eq_h}).  There is no strong physical motivations for this
modification but, as discussed by \cite{FargeSadourny1989}, molecular
dissipation of the form $\nu \bnabla^2 \uu$ is not necessarily a
relevant model of the actual small-scale dissipation for shallow-water
flows, which should rather be described as a transition from
two-dimensional to three-dimensional motions before reaching the
scales where dissipation actually occurs.

Equations (\ref{eqqnum}-\ref{eqapmnum}) are simulated by means of a
pseudo-spectral method with periodic boundary conditions.
%
Time advancement is carried out by a classical fourth-order
Runge-Kutta scheme for the nonlinear term and an exact integration for
the linear and dissipative terms.  This explicit integration is
especially interesting at very high resolution and very large $c$ when
the shortest waves are very fast with frequency of the order of
$\omega \simeq c \max(k)$.
%
We use an adaptable time step method which maximizes the time step
over a standard Courant-Friedrichs-Lewy condition
\cite[]{Lundbladh1999, AugierChomazBillant2012}.
%
Most of the aliasing is removed by truncating 8/9 of the modes along
each direction \cite[for a detail discussion on the issues of the
non-conservation of the non-quadratic energy and the aliasing errors
in the truncated one-layer shallow water model,
see][]{FargeSadourny1989}.

\subsection{Forced dissipative statistically stationary simulations}

We have carried out a number of simulations
with large-scale forcing and small-scale dissipation
for different resolutions and different values of the wave speed.
%
The resolution is characterized by the number of nodes in the each
direction, $n$, and has been varied from 240 to 7680.
%
The wave speed $c$ has been varied over two orders of magnitude from
10 to 1000.
%
Table~\ref{tab} presents the parameters for a set of representative
simulations.

\begin{table}
  \begin{center}
% \def~{\hphantom{0}}
\begin{tabular}{cc@{\hskip 8mm}c@{\hskip 8mm}cccc@{\hskip 8mm}cc}
$n$ & $c$ & $\nu_8$ & $\eps$ & $\displaystyle\frac{\kmax}{\kdiss}$ & $\displaystyle\frac{\kdiss}{k_f}$ & $F_f$ & $\min h$ & $\displaystyle\frac{\max |\uu|}{c}$ \\[3mm]
~960 &   10 & 1.5e-10 & 1.03 & 2.46 &  29 &  0.111 & 0.25 & 0.96 \\
1920 &   10 & 9.6e-13 & 1.00 & 2.46 &  58 &  0.110 & 0.37 & 0.92 \\
3840 &   10 & 6.0e-15 & 1.01 & 2.46 & 116 &  0.110 & 0.39 & 1.01 \\
7680 &   10 & 3.7e-17 & 1.03 & 2.46 & 231 &  0.111 & 0.32 & 0.95 \\[1mm]
~960 &   20 & 1.5e-10 & 0.98 & 2.47 &  29 &  0.055 & 0.65 & 0.51 \\
1920 &   20 & 9.6e-13 & 0.84 & 2.48 &  57 &  0.052 & 0.66 & 0.81 \\
3840 &   20 & 6.0e-15 & 0.99 & 2.46 & 115 &  0.055 & 0.56 & 0.68 \\[1mm]
~960 &   40 & 1.5e-10 & 0.99 & 2.46 &  29 &  0.027 & 0.81 & 0.24 \\
1920 &   40 & 9.6e-13 & 1.01 & 2.46 &  58 &  0.028 & 0.78 & 0.28 \\
3840 &   40 & 6.0e-15 & 0.98 & 2.47 & 115 &  0.027 & 0.77 & 0.29 \\
7680 &   40 & 3.7e-17 & 0.94 & 2.47 & 230 &  0.027 & 0.76 & 0.32 \\[1mm]
~960 &  100 & 1.5e-10 & 0.99 & 2.46 &  29 &  0.011 & 0.89 & 0.09 \\
1920 &  100 & 9.6e-13 & 0.98 & 2.47 &  58 &  0.011 & 0.90 & 0.11 \\
3840 &  100 & 6.0e-15 & 0.97 & 2.47 & 115 &  0.011 & 0.87 & 0.13 \\[1mm]
~960 &  200 & 1.5e-10 & 0.99 & 2.46 &  29 &  0.005 & 0.95 & 0.05 \\
1920 &  200 & 9.6e-13 & 0.99 & 2.46 &  58 &  0.005 & 0.94 & 0.06 \\
3840 &  200 & 6.0e-15 & 0.90 & 2.47 & 115 &  0.005 & 0.94 & 0.06 \\[1mm]
~960 &  400 & 1.5e-10 & 0.97 & 2.47 &  29 &  0.003 & 0.97 & 0.03 \\
1920 &  400 & 9.6e-13 & 0.99 & 2.46 &  58 &  0.003 & 0.96 & 0.03 \\[1mm]
~960 & 1000 & 1.5e-10 & 1.16 & 2.45 &  29 &  0.001 & 0.98 & 0.01 \\
1920 & 1000 & 9.6e-13 & 0.91 & 2.47 &  57 &  0.001 & 0.98 & 0.01 \\
\end{tabular}
\caption{Overview of parameters for a set of representative simulations.
The number of nodes in the each direction is denoted by $n$.
The size of the numerical domain is equal to $L_h = 50$.
Only the wave numbers $5\delta k\leqslant|\kk|\leqslant8\delta k$ are forced
and the forcing wave number is defined as
$k_f \equiv 6 \delta k$
corresponding to a characteristic forcing scale of approximately
$L_f \equiv \pi/k_f = 3.57$.
%
$F_f = \eps^{1/3}/({k_f}^{1/3}c)$ is the forcing Froude number and
$\max |\uu|/c$ is the spatial and temporal maximum of a local Froude
number.  }
\label{tab}
\end{center}
\end{table}

The ageostrophic variable $a$ is forced in a shell in spectral space
corresponding to relatively small wave numbers $5\delta k\leqslant
|\kk| \leqslant 8\delta k$, where $\delta k = 2\pi/L_h$.
%
\Add{In the following, we use $L_h = 50$ in order to obtain a
characteristic forcing wave number of order unity, $k_f \equiv 6
\delta k \simeq 0.75$. The corresponding forcing scale is $L_f \equiv
\pi/k_f \simeq 4.2$.}
%
Since only the ageostrophic variable is forced ($\hat f_d = 0$),%
(i) only the thickness fluctuation $\eta$ is forced in the
non-rotating case and %
(ii) the force terms in (\ref{eqapmnum}) are simply equal to $\hat
f_\pm = \hat f_a/2$.
%
In order to compute the force $\hat f_a$, we start from a
pre-normalized force $\hat f_{0}$ obtained from a normal random
process decorrelated in time.
%
The force is then normalized such that the quadratic part of the total
energy $\langle|\uu|^2 + c^2 \eta^2\rangle/2$ is injected at a
constant rate.
%
The spectral injection rate of the quadratic energy averaged over one
time step is (see appendix~\ref{app_comp})
\begin{equation}
P_q(\kk, t)
=
\Re\{ \hat \uu(\kk)^* \cdot \hat \ff(\kk)
+
c^2 \hat \eta(\kk)^* \hat f_\eta(\kk) \}
+
(|\hat\ff|^2 + c^2 |\hat f_\eta|^2) \delta t /2,
\end{equation}
where $\Re$ denotes the real part.
%
Writing $\hat f_a = \alpha \hat f_{0}$, it is straightforward to solve
a second-order equation for the coefficient $\alpha$ in order to fix
the injection rate $\Add{P_0 \equiv} \sum_\kk P_q(\kk, t)$ to unity.

The energy is dissipated at the smallest resolved scales by a
hyper-viscous operator, corresponding to a dissipative frequency equal
to $\fdiss(\kk) = \nu_n |\kk|^n$, with $n = 8$.  The value of the
hyperviscosity $\nu_8$ is chosen such as the hyper-Kolmogorov wave
number
\begin{equation}
k_{Kn} = \left( \frac{{\nu_n}^3}{\eps} \right)^\frac{1}{3n-2},
\end{equation}
is well resolved, $\kdiss =k_{K8} \simeq \kmax/ 2.5$, where $\kmax =
(8/9)\pi n/L_h$ is the maximum resolved wave number.

We have observed that when only the waves are forced, the vorticity
does not increase and that when the vorticity is small enough, it does
not significantly influence the waves.  Therefore, we have chosen not
to simulate a negligible vorticity field and to only solve equations
(\ref{eqapmnum}) with $\zeta = 0$.

\begin{figure}
\centerline{\includegraphics[width=13cm]{../Figs/fig_Emean_time}}
\caption{Space averaged energy
$\langle h|\uu|^2 + c^2 h^2 \rangle/2$ versus time
for different wave speeds $c$ and resolutions $n$.
%
The energy and the time are normalized by
$E_f\equiv (P_0/k_f)^{2/3}$ and $T_f\equiv (P_0 {k_f}^2)^{-1/3}$,
with $P_0 = 1 \simeq \eps$.
%
The colors corresponds to different wave speeds as indicated in the figure
$c= 10$, 20, 40, 70, 100, 200, 400, 700 and 1000.
%
The different resolutions are represented by different types of lines:
\Add{thin continuous lines, $n = 240$;
thick dashed lines, $n = 480$;
thin dotted lines, $n = 960$;
thick continuous lines, $n = 1920$;
thin dashed lines, $n = 3840$;
thick dotted lines, $n = 5760$
and
thin dotted dashed lines, $n = 7680$.}
}
\label{fig_Evstime}
\end{figure}

The time evolution of the instantaneous total energy is shown in
figure~\ref{fig_Evstime} for different wave speeds $c$.
%
The resolution \Add{and the dissipation wave number are} progressively
increased: %
$n = 240$ ($0\leqslant t/T_f \leqslant 100$), %
$n = 480$ ($100\leqslant t/T_f \leqslant 125$), %
$n = 960$ ($125\leqslant t/T_f \leqslant 140$), %
$n = 1920$, %
$n = 3840$, %
$n = 5760$ and %
$n = 7680$\Add{, where $T_f\equiv
(P_0 {k_f}^2)^{-1/3}$ is the characteristic forcing time}.
%
Each time the resolution is increased, the energy first sharply
increases and then fluctuates.  For most of the simulations, it is
clear that a statistically stationary regime is reached.
%
However,
%
\Remove{in the relatively short simulations at the highest
resolution for the largest wave speeds ($n = 1920$, $c = 700$ and
1000),}
%
\Add{for some relatively short simulations with very large wave speed
and/or very large resolution,}
%
there are large fluctuations and it is not absolutely certain whether
a statistically stationary regime is reached.
%
\Add{This is in particular the case for the simulations for $c = 700$, $n
= 1920$ (thick red continuous line), $c = 200$, $n = 3840$ (thin
magenta dashed line) and $c=40$, $n = 7680$ (thin blue dotted dashed
line).}
%
\Add{Note that these simulations are already quite numerically
costly. For example, the simulation for $c=1000$ and $n = 1920$
during slightly less than $20T_f$ corresponds to approximately
$8\times 10^5$ time steps.}

Since the energy is injected at large scales and dissipated only at
the smallest resolved scales, the existence of a statistically
stationary regime implies a downscale flux of energy, which is equal
to the large-scale energy injection rate.
%
For the same energy injection rate and resolution, the mean energy
increases with the wave speed, implying that when $c$ increases the
mean energy has to be larger to lead to the same downscale energy
flux.
%
The results presented in the following are from the statistically
stationary regime.  Apart from the snapshots, all shown quantities are
averaged over a period corresponding to this regime.

Table~\ref{tab} presents numerical and physical quantities for a set
of representative simulations.
%
We characterize the simulations by the forcing Froude number
\begin{equation}
F_f \Add{\equiv} \frac{\eps^{1/3}}{{k_f}^{1/3}c}.
\end{equation}
\Add{Since the characteristic forcing wave number and the dissipation
rate are approximately equal to $k_f \equiv 6 \delta k \simeq 0.75$
and $\eps \simeq P_0 = 1$, the forcing Froude number is approximately
inversely proportional to the wave speed: $F_f \simeq 1.1/c$. This
allows us to simply use the wave speed to denote the simulations.}
% where $k_f \equiv 6 \delta k = 0.75$ is a wave number characterizing
% the forcing.
%
The ratio $\kdiss/k_f$ gives an order of magnitude of the width of the
inertial range.  It is a physical quantity related to the numerical
resolution on which the flow can depend.
%
Table~\ref{tab} also displays the minimum thickness $\min(h)$
characterizing the importance of the non-quadraticity of the energy,
and $\max(|\uu|/c)$, which can be interpreted as the maximum of a
local Froude number.


\documentclass[12pt]{article}
\newcommand{\N}{\mathrm{N}}
\newcommand{\m}{\mathrm{m}}
\newcommand{\cm}{\mathrm{cm}}
\newcommand{\s}{\mathrm{s}}
\renewcommand{\min}{\mathrm{min}}
\renewcommand{\l}{\ell}
\newcommand{\C}{\mathrm{deg\,C}}
\newcounter{problem}
\begin{document}\thispagestyle{empty}

\section*{NYU General Physics 1---Problem set 13}

\paragraph{Problem~\theproblem:}\refstepcounter{problem}%
In lecture we discussed the pressure gradient in a bus accelerating at
$2\,\m\,\s^{-2}$.

\textsl{(a)} By thinking about the size of the interior of the bus,
the density of air, and so on, compute roughly the \emph{horizontal}
pressure difference inside the bus.  That is, how much larger is the
pressure at the back of the bus than the front of the bus?  (If it is
at all confusing to you that the equal-pressure surfaces are slanted,
consider the pressure difference between a point at the front of the
bus and a point at the back of the bus, where both points are at the
same height above ``sea level''.)  Give your answer in both
$\N\,\m^{-2}$ and atmospheres.

\textsl{(b)} What things did you have to assume to give your answer?
Why did we assume that the windows on the bus are all closed?
What do you think happens if the windows all along the bus
\emph{aren't} closed?

\paragraph{Problem~\theproblem:}\refstepcounter{problem}%
Blood flows through the aorta at a volumetric rate of something like
$5\,\l\,\min^{-1}$.

\textsl{(a)} If the aorta has a diameter of $3.5\,\cm$, at what speed
$v$ does the blood flow?  Did you have to make any assumptions to
answer that?

\textsl{(b)} Imagine that, because of a pathology, over a $20\,\cm$
length, the aorta narrows to $2.5\,\cm$ in diameter.  What is the
velocity change $\Delta v$ from one end of this to the other?

\textsl{(c)} Consider a little cube of blood in the part of the aorta
that is getting narrower.  Give the cube a side length $\Delta x$ and
note that it is \emph{accelerating}.  What---qualitatively---does this
mean about the pressure in the aorta?  Ignore gravity for this
problem; imagine that all blood flow is driven by blood pressure (this
is true if the patient is lying down).

\textsl{(d)} In preparation for part \textsl{(e)}, find a combination
of speed $v$ and mass density (mass per volume) $\rho$ that has
dimensions of pressure.  Look up the density of blood and compute the
pressure corresponding to the velocity $v$ you found in
part \textsl{(a)}.

\textsl{(e)} Compute the pressure change from one end of this
narrowing aorta to the other end, by thinking about the pressure
gradient at each point that produces the necessary local acceleration.
\emph{Note: This is not easy!}  Compare your result to normal mean
human blood pressure.  Discuss with your friends and colleagues.

\paragraph{Problem~\theproblem:}\refstepcounter{problem}%
[\textsl{optional}] What is the most expensive ingredient of a
standard American Thanksgiving dinner, \emph{by weight}?  (That is, by
dollars per pound.)  How does this value compare to the dollars per
pound of gold we computed in Problem~Set~1?  What does all this have
to do with the history of Western Civilization?

\end{document}


\documentclass{article}
\usepackage[utf8]{inputenc}

\title{MAT257 Notes}
\author{Jad Elkhaleq Ghalayini}
\date{September 14 2018}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage{enumitem}
\usepackage{graphicx}
\usepackage{cancel}

\usepackage[margin=1in]{geometry}

\newtheorem{theorem}{Theorem}
\newtheorem{lemma}{Lemma}
\newtheorem{definition}{Definition}
\newtheorem*{corollary}{Corollary}
\newtheorem{exercise}{Exercise}

\newcommand{\reals}[0]{\mathbb{R}}
\newcommand{\nats}[0]{\mathbb{N}}
\newcommand{\ints}[0]{\mathbb{Z}}
\newcommand{\rationals}[0]{\mathbb{Q}}
\newcommand{\brac}[1]{\left(#1\right)}
\newcommand{\sbrac}[1]{\left[#1\right]}
\newcommand{\mc}[1]{\mathcal{#1}}
\newcommand{\eval}[3]{\left.#3\right|_{#1}^{#2}}
\newcommand{\ip}[2]{\left\langle#1,#2\right\rangle}

\begin{document}

\maketitle

\section*{Continuity}

\begin{definition}
  Consider a function \[f: A \to \reals^n\]
\end{definition}
\(f\) is \underline{continuous} at \(A\) if for every \(\epsilon > 0\), \(\exists \delta > 0\) such that \(|f(x) - f(a)| < \epsilon\) whenever \(|x - a| < \delta, x \in A\).
\begin{theorem}
  \(f\) is continuous if and only if for every open \(U \subset \reals^n\), \(f^{-1}(U) = A \cap V\) where \(V\) is open in \(\reals^n\).
\end{theorem}
\begin{proof}

  \begin{itemize}

    \item [\(\implies\)] consider \(U\) open in \(\reals^n\). Let \(a \in f^{-1}(U)\). For some \(\epsilon > 0\), \(\exists\) a ball \(B_{f(a)} = B(f(a), \epsilon) \subset U\) because \(U\) is open.

    Since \(f\) is continuous at \(a\), \(\exists \delta > 0\) such that \(f(x) \in B_{f(a)}\) for every \(x \in A \cap B(a, \delta) = B_a\). We can define
    \[V = \bigcup_{a \in f^{-1}(U)}B_a\]

    \item [\(\impliedby\)] Consider \(a \in A\) and let \(\epsilon > 0\). Let \(U = B(f(a), \epsilon)\). Then \(f^{-1}(U) = A \cap V\) for some open \(V \subset \reals^n\).
    \[a \in V \implies \exists \delta > 0, B(a, \delta) \subset V\]
    But everything which lies inside \(V\) gets mapped inside \(U\) which is that first ball that we started with. And this is the condition that we want.

  \end{itemize}
\end{proof}

\begin{corollary}
  A composite of continuous functions is continuous
\end{corollary}
\begin{proof}
  Let
  \[f: A \to \reals^n, g: B \to \reals^p\]
  be continuous functions where \(B \subset \reals^n\) and \(f(A) \subset B\).

  Consider open \(U \subset \reals^p\). We know
  \[\exists V \subset \reals^n \text{ open, } g^{-1}(U) = B \cap V\]
  So we can write
  \[(g \circ f)^{-1}(U) = f^{-1}(g^{-1}(U)) = f^{-1}(B \cap V) = f^{-1}(V)\]
  We know that
  \[\exists W \subset \reals^n \text{ open, }, f^{-1}(V) = A \cap W = (g \circ f)^{-1}(U)\]
  But this is exactly what we wanted to show
\end{proof}

\begin{exercise}
  Let \(f = (f_1,...,f_n)\) be a function from \(\reals\) to \(\reals^n\). Then \(f\) is continuous if and only if \(\forall i \in \{1,...,n\}\), \(f_i\) is continuous.
\end{exercise}
\begin{proof}
  \begin{itemize}

    \item [\(\impliedby\)] We need to estimate the norm \(|f(x) - f(a)|\) with the differences between \(f_i(x_i)\) and \(f_i(a_i)\). We could use a variety of inequalities for this, including
    \[|f(x) - f(a)| \leq \sum_{i = 1}^n|f_i(x) - f_i(a)|\]
    The full \(\epsilon\)-\(\delta\) argument is left as an exercise.

    \item [\(\implies\)] We need to estimate the norm \(|f_i(x) - f_i(a)| < |f(x) - f(a)|\). Alternatively, we can do this topologically. The full argument is left as an exercise.

  \end{itemize}

\end{proof}
\begin{exercise}
  A linear transformation \(T: \reals^m \to\reals^n\) is \underline{uniformly} continuous
\end{exercise}
\begin{definition}
   There is a norm \(M > 0\) such that \(|T(x)| \leq M|x|\). Hence,
   \[|T(x) - T(y)| = |T(x - y)| \leq M|x - y|\]
   Given \(\epsilon\), take \(\delta = \frac{\epsilon}{M}\).
\end{definition}
\begin{exercise}
  Are the following functions continuous?
  \begin{enumerate}
    \item \(f(x, y) = \frac{x^2 - y^2}{x^2 + y^2}\) - No
    \item \(f(x, y) = \frac{x^2 + 3xy + y^2}{x^2 + 4xy + y^2}\) - No
    \item \(f(x, y) = e^{-\frac{|x - y|}{x^2 - 2xy + y^2}} = e^{-\frac{1}{|x - y|}}\) - Yes
  \end{enumerate}
\end{exercise}
\begin{proof}
  \begin{enumerate}
    \item \(f\) is 1 along the line \(\{f(x, 0) : x \in \reals\}\), but -1 along the line \(\{f(0, y) : y \in \reals\}\), both of which traverse the origin.
    \item No for the same reason, but we can't check on the axes, since each axis is 1. Instead, we can check on the \(x\) axis and compare that with any line except the \(y\) axis, such as \(y = x\), where the value is \(\frac{5}{6}\)
    \item Composite of \(z \mapsto e^{\frac{1}{|z|}}\) and \((x, y) \mapsto x - y\)
  \end{enumerate}
\end{proof}
\begin{exercise}
  Let \(X \subseteq \reals^n\). We define the \underline{distance function}
  \[d(x, X) = \inf_{a \in X}|x - a|\]
  \(\forall X \in \mc{P}(\reals^n), d(x, X)\) is uniformly continuous on \(\reals^n\)
\end{exercise}

\end{document}


\problemname{Chocolates}

\textit{``My mom always said life was like a box of chocolates. You never know what you're gonna get."}\\

Forrest Gump is a young boy who goes to Greenbow County Central School. As a child, he enjoys running, dancing by swinging his hips, and eating chocolates. Most of all, he enjoys spending time with his best friend Jenny. However, Forrest isn't the brightest boy by conventional means. While he fully embraces the life wisdom that his mama often imparts (such as through analogies with boxes of chocolates), he still has trouble keeping up with his classes.\\

Forrest's math class is currently learning about shapes, specifically polygons. Forrest is falling behind because he doesn't really understand what a polygon is. Jenny knows that if Forrest doesn't keep up, his mama would have to take drastic measures to prevent the crooked principal, Mr. Hancock, from transferring Forrest to a special school. As such, Jenny has decided take Forrest's schooling into her own hands.\\

Jenny has decided to use something that Forrest understands to explain polygons to him. She picks up a box of square chocolates and empties the pieces onto a napkin, leaving an empty box with $R$ rows and $C$ columns of empty cells. She places a single piece of chocolate in the box and says ``\textit{With one chocolate here, I've made a square. A square is a polygon, Forrest.}"

\begin{center}\includegraphics[width=100pt]{chocolates1.png}\end{center}

Jenny added two more chocolates around the first one and said, ``\textit{We still have here a polygon, because we can trace a border around the chocolates without our fingers leaving the surface of the box.}"

\begin{center}\includegraphics[width=100pt]{chocolates2.png}\end{center}

Jenny adds some more chocolates, filling up the entire box except a hole in the middle. ``\textit{Now Forrest, no matter how we trace the outside box, there will always be a hole we can never draw unless our finger leaves the surface. So this here ain't a polygon.}"

\begin{center}\includegraphics[width=100pt]{chocolates3.png}\end{center}

Jenny removes a chocolate from the corner and says, ``\textit{Now we're back to a polygon again! As long as we can trace the border of our chocolates without crossing over where we already traced, we have ourselves here a polygon. As we trace, we can even have two corners barely touch, so long as we don't overlap any border line we've already gone over.}".

\begin{center}\includegraphics[width=100pt]{chocolates4.png}\end{center}

``\textit{That's amazing Jenny. Even with just a small box like that, it seems like you can make so many of 'em}", said Forrest.\\

``\textit{That's right Forrest!}", said Jenny. ``\textit{There's so many ways to make a polygon using this box of chocolates, if I just made one at random and had you guess, you truly are never gonna know what you're gonna get!}"\\

``\textit{Well, Jenny. Just how many ways do you think are there?}" asked Forrest.\\

``\textit{Hmm, I'm not quite sure about that Forrest.}" Jenny thought for a moment. "\textit{You really have me stumped.}"\\

Jenny wants to impress Forrest with the answer. Given the dimensions of the chocolate box, can you help her count the number of ways? For example, a $2$ by $2$ chocolate box has $13$ ways of forming a polygon:
\begin{verbatim}
   x.   .x   ..   ..   xx   x.   ..   .x   xx   .x   xx   x.   xx
   ..   ..   x.   .x   ..   x.   xx   .x   x.   xx   .x   xx   xx
\end{verbatim}

\section*{Input}
The first and only line of input consists of two space-separated integers $R$ and $C$ ($1 \leq R, C \leq 4$), specifying the dimensions of the box of chocolates.

\section*{Output}
Print, on a single line, the number of different ways that chocolates can form a single polygon in the box. Note that if the same polygon can be placed at multiple different places in the box, then all of those ways are counted separately towards the answer.\\