\documentclass[twoside]{MATH77}
\usepackage[\graphtype]{mfpic}
\usepackage{multicol}
\usepackage[fleqn,reqno,centertags]{amsmath}
\begin{document}
\opengraphsfile{pl02-05}
\hyphenation{ODSBESJN}
\begmath 2.5 Bessel Functions of General Orders $J_\nu $ and $Y_\nu $

\silentfootnote{$^\copyright$1997 Calif. Inst. of Technology, \thisyear \ Math \`a la Carte, Inc.}

\subsection{Purpose}

These subroutines compute a sequence of values $J_\nu (x)$ or $Y_\nu (x)$
for $\nu = \alpha $, $\alpha + 1$, ..., $\alpha +\text{NUM} - 1$. $J_\nu $
and $Y_\nu $ are Bessel functions of the first and second kinds,
respectively, as described in \cite{ams55:bes}. $J_\nu $ and $Y_\nu $ are a
pair of linearly independent solutions of the differential equation
\begin{equation*}
x^2\frac{d^2w}{dx^2} + x\frac{dw}{dx} + (x^2 - \nu ^2)w = 0
\end{equation*}
$Y_\nu $ is also sometimes called the Neumann function and denoted by $N_\nu
.$

\subsection{Usage}

\subsubsection{Program Prototype, Single Precision}

\begin{description}
\item[REAL]  \ {\bf X, ALPHA, BJ}($\geq $NUM){\bf ,BY}($\geq $NUM)

\item[INTEGER]  \ {\bf NUM}
\end{description}

Assign values to X, ALPHA, and NUM. To evaluate J Bessel functions:
$$
\fbox{{\bf CALL SBESJN (X, ALPHA, NUM, BJ)}}
$$
To evaluate Y Bessel functions:
$$
\fbox{{\bf CALL SBESYN (X, ALPHA, NUM, BY)}}
$$
The results are stored in BJ() or BY(), respectively.

\subsubsection{Argument Definitions}

\begin{description}
\item[X]  \ [in] Argument for function evaluation. Require X $\geq 0$ for
the J function and X $>0$ for the Y function. Require X $<(16\rho
)^{-1}$ for both functions, where $\rho $ denotes the machine
precision.

\item[ALPHA]  \ [in] Lowest order, $\nu $, for which $J_\nu (x)$ or $Y_\nu
(x)$ is to be computed. Require ALPHA $\geq 0$. For sufficiently large $\nu $%
, depending on $x$, positive values of $J_\nu (x)$ will be smaller than the
computer's underflow limit and the magnitude of $Y_\nu (x)$ will exceed the
overflow limit. SBESYN issues an error message before overflow occurs.

\item[NUM]  \ [in] Number of values of $\nu $ for which $J_\nu (x)$ or $%
Y_\nu (x)$ is to be computed. Require NUM $\geq 1.$

\item[BJ()]  \ [out] Array in which SBESJN will store results. BJ($%
i)=J_{\alpha +i-1}(x)$ for $i=1$, 2, ..., NUM.

\item[BY()]  \ [out] Array in which SBESYN will store results. BY($%
i)=Y_{\alpha +i-1}(x)$ for $i=1$, 2, ..., NUM.
\end{description}

\subsubsection{Modifications for Double Precision}

For double precision usage, change the REAL statement to DOUBLE PRECISION
and change the subroutine names to DBESJN and DBESYN, respectively.

\subsection{Examples and Remarks}

These Bessel functions satisfy the Wronskian identity (\cite{ams55:bes},
Eq.\,9.1.16)
\begin{equation*}
z(\nu ,x) = \frac{x\pi }{2} \left[J_{\nu +1}(x) Y_\nu (x) - J_\nu (x) Y_{\nu
+1}(x)\right] - 1 = 0
\end{equation*}
The program DRSBESJN evaluates this expression for a few values of $\nu $
and $x$. The results are shown in ODSBESJN.

\subsection{Functional Description}

\subsubsection{Properties of J and Y}

In the region $x \geq \nu $, both J and Y are oscillatory and are bounded in
magnitude by one. For fixed $\nu \geq 0$ and increasing $x$ these functions
have asymptotic behavior described by (\cite{ams55:bes}, Eqs.\,9.2.1~--~9.2.2)
\begin{align}
\label{O1}J_\nu (x) &\sim [2/(\pi x)]^{1/2} \cos (x-(\nu + 0.5)\pi /2)
\hspace{-1in}\\
\label{O2}Y_\nu (x) &\sim [2/(\pi x)]^{1/2} \sin (x - (\nu + 0.5)\pi /2)
\hspace{-1in}
\end{align}
In the region $\nu \geq x$, $J_\nu (x)$ is positive and bounded and
approaches zero as $\nu $ increases with fixed $x > 0$, while $Y_\nu (x)$ is
negative and unbounded and approaches $-\infty $ as $\nu $ increases with
fixed $x > 0$. For fixed $x > 0$ and increasing $\nu $, these functions have
asymptotic behavior described by (\cite{ams55:bes}, Eqs.\,9.3.1~--~9.3.2).
\begin{align}
\label{O3}J_\nu (x) &\sim (2\pi \nu )^{-1/2}(ex/(2\nu ))^\nu\\
\label{O4}Y_\nu (x) &\sim -(2/(\pi \nu ))^{\frac{1}{2}}(ex/(2\nu))^{-\nu}
\end{align}
where $e = 2.718\cdots .$

Both J and Y satisfy the recursion (\cite{ams55:bes}, Eq.\,9.1.27)
\begin{equation}
\label{O5}f_{\nu +1}(x) - (2\nu /x) f_\nu (x) + f_{\nu - 1}(x) = 0
\end{equation}
For $\nu > x$ this recursion is stable in the forward direction for Y and in
the backward direction for J. For $x > \nu $ the recursion is stable in
either direction for both J and Y.

%\vspace{10pt}
% \hspace{.3in}\mbox{\input pl02-05a }\vspace{12pt}
%\centerline{$x$}
%\centerline{Figure 1. ~ $J_{\nu}(x)$}
%\vspace{15pt}

%\vspace{10pt}

% \hspace{.3in}\mbox{\input pl02-05b }\vspace{12pt}
%\centerline{$x$}
%\centerline{Figure 2. ~ $Y_{\nu}(x)$}\vspace{10pt}
%
\subsubsection{Machine dependent quantities}

Let $\rho $ denote the machine precision, $i.e.$, R1MACH(3) or
D1MACH(3) of Chapter~19.1. Let $\Omega $ denote the overflow limit, $i.e.$,
R1MACH(2) or D1MACH(2). Define
\begin{equation*}
\mathit{XPQ} = 1.1293(-\log _{10}(\rho /4)) - 0.59
\end{equation*}
The asymptotic series used in these subroutines is valid for $x \geq
\mathit{XPQ}$ and $0 \leq \nu \leq 2.$

Let $\nu ^*(x)$ denote the value of $\nu $ for which Eq.\,(4) reaches the overflow
limit, $\Omega $, for a given value of $x$. It happens that $\nu ^*(x)$ is very
close to the value of $\nu $ for which Eq.\,(3) reaches the underflow limit on the
same machine. The figure below shows plots of $\nu ^*(x)$ for some
computer systems currently in use at JPL.
\vspace{5pt}

\mbox{\input pl02-05c }

%\centerline{$x$}
%\centerline{Figure 3. ~Underflow limit for $J_{\nu}$; overflow limit
%for $Y_{\nu}$}\vspace{5pt}

\subsubsection{Computation of $J_\nu (x)$}

Given $x$, $\alpha $, and NUM, define $\beta = \alpha +\text{NUM} - 1$.
Thus, $\beta $ is the largest requested order.

For $x = 0$ the result is 1 if $\nu = 0$, and 0 if $\nu > 0.$

For $0 < x \leq 0.1$ the Taylor series in $x$ is used
(\cite{ams55:bes},Eq.\,9.1.10).  For $0.1 < x \leq \max (\beta ,
\mathit{XPQ})$ forward recursion on $\nu $ is used to determine a starting
point for backward recursion.  The execution time in this region increases
linearly with $\beta $ and can be substantial for large $\beta .$

For $\max (\beta , \mathit{XPQ}) < x < (16\rho )^{-1}$ the subroutine
evaluates the asymptotic series in $x$ (\cite{ams55:bes}, Eqs.\,9.2.5,
9.2.9, and~9.2.10) for two values of $\nu $ in the range [0,~2], and then
uses forward recursion.  The execution time in this region increases
linearly with $\beta $ and decreases with increasing $x.$

If $x > (16\rho )^{-1}$ an error message is issued
because the phase of the sine and cosine functions will not be known with
any accuracy.

\subsubsection{Computation of $Y_\nu (x)$}

If $x = 0$ an error message is issued since the result would be $-\infty $.
The output values are set to $-\Omega /2.$

For $0 < x \leq \rho $ and $\nu = 0$, the result is $(2/\pi ) (\gamma +\ln
(x/2))$ (\cite{ams55:bes}, Eq.\,9.1.13), where $\gamma $ denotes Euler's
constant, $0.57721\cdots$.  For $0 < x \leq \rho $ and $\nu > 0$, the result is
$-\pi ^{-1} \Gamma (\nu ) (x/2)^{-\nu }$ (\cite{ams55:bes}, Eq.\,9.1.9).

For $\rho < x < \mathit{XPQ}$ the subroutine first computes values of J. From
these values it computes Y for two values of $\nu $ in [0,~2], and then uses
forward recursion on $\nu $ to obtain the requested values.

For $\mathit{XPQ} \leq x \leq (16\rho )^{-1}$ the subroutine evaluates the
asymptotic series in $x$ for two values of $\nu $ in [0,~2], and then uses
forward recursion.

If $x > (16\rho )^{-1}$ an error message is issued as noted
previously for J.

\subsubsection{Accuracy tests}

The subroutines SBESJN and SBESYN were tested on an
IBM compatible PC using IEEE arithmetic by comparison with
the corresponding double precision subroutines.  Tables 1 and
2 give a summary of the errors found in these tests.  Each
number in a rectangular cell is the maximum value of the
error observed at 2592 points tested in the indicated range.
Each number in a triangular cell is the maximum over 1296
points.  The underflow limit for $J_{\nu}$, and the overflow
limit for $Y_{\nu}$, actually extend down the $\nu $ axis
(see Figure~3).  Where the function underflows or overflows,
fewer samples are used.

\begin{quote}Table 1. Maximum errors found in indicated regions for SBESJN.
Relative error is shown above the diagonal and absolute error below. Error
is shown as a multiple of the machine precision, $\approx 1.19
\times 10^{-7}$ for these tests.
\end{quote}\vspace{10pt}

\setlength{\unitlength}{1pt}
\begin{picture}(218, 160)(-36, -20)
\put(-30, 75){$\nu$}
\multiput(0, 0)(0, 25){7}{\line(1, 0){180}}
\put(0, 0){\line(0, 1){150}}
\put(30, 0){\line(0, 1){125}}
\multiput(60, 0)(30, 0){5}{\line(0, 1){150}}
\put(-2, -10){0}
\put(28, -10){2}
\put(58, -10){5}
\put(85, -10){10}
\put(115, -10){20}
\put(144, -10){50}
\put(170, -10){100}
\put(-24, -10){\makebox(20, 20)[r]{0}}
\put(-24, 15){\makebox(20, 20)[r]{2}}
\put(-24, 40){\makebox(20, 20)[r]{5}}
\put(-24, 65){\makebox(20, 20)[r]{10}}
\put(-24, 90){\makebox(20, 20)[r]{20}}
\put(-24, 115){\makebox(20, 20)[r]{50}}
\put(-24, 140){\makebox(20, 20)[r]{100}}
\put(0, 0){\line (6, 5){180}}
\put(90, -20){$x$}
\put(0, 125){\makebox(60, 25){\small OVERFLOW}}
\put(0, 100){\makebox(30, 25){17}}
\put(0, 75){\makebox(30, 25){27}}
\put(0, 50) {\makebox(30, 25){10}}
\put(0, 25) {\makebox(30, 25){4}}
\put(0, 0)    {\makebox(30, 25){~\raisebox{5pt}{2} \hfill
\raisebox{-5pt}{1}~}}
\put(30, 100){\makebox(30, 25){17}}
\put(30, 75){\makebox(30, 25){10}}
\put(30, 50) {\makebox(30, 25){7}}
\put(30, 25) {\makebox(30, 25){~\raisebox{5pt}{3} \hfill
\raisebox{-5pt}{1}~}}
\put(30, 0)    {\makebox(30, 25){1}}
\put(60, 125){\makebox(30, 25){18}}
\put(60, 100){\makebox(30, 25){24}}
\put(60, 75){\makebox(30, 25){10}}
\put(60, 50){\makebox(30, 25){~\raisebox{5pt}{5} \hfill
\raisebox{-5pt}{2}~}}
\put(60, 25) {\makebox(30, 25){1}}
\put(60, 0) {\makebox(30, 25){1}}
\put(90, 125){\makebox(30, 25){30}}
\put(90, 100){\makebox(30, 25){26}}
\put(90, 75){\makebox(30, 25){~\raisebox{5pt}{9} \hfill
\raisebox{-5pt}{4}~}}
\put(90, 50){\makebox(30, 25){2}}
\put(90, 25) {\makebox(30, 25){1}}
\put(90, 0) {\makebox(30, 25){1}}
\put(120, 125){\makebox(30, 25){44}}
\put(120, 100){\makebox(30, 25){~\raisebox{5pt}{21} \hfill
\raisebox{-5pt}{27}~}}
\put(120, 75){\makebox(30, 25){4}}
\put(120, 50){\makebox(30, 25){2}}
\put(120, 25) {\makebox(30, 25){2}}
\put(120, 0) {\makebox(30, 25){2}}
\put(150, 125){\makebox(30, 25){~\raisebox{5pt}{39} \hfill
\raisebox{-5pt}{96}~}}
\put(150, 100){\makebox(30, 25){16}}
\put(150, 75){\makebox(30, 25){3}}
\put(150, 50){\makebox(30, 25){3}}
\put(150, 25) {\makebox(30, 25){3}}
\put(150, 0) {\makebox(30, 25){3}}
\end{picture}

As a test of the double precision subroutines, and an additional test of the
single precision subroutines, the expression $z(\nu ,x)$ defined in Section
C was evaluated at 40 points. Nine values are shown in Table 3 from these
tests of SBESJN and SBESYN and in Table 4 from the tests of DBESJN and
DBESYN.

These subroutines are designed for use with arithmetic precision to about $%
10^{-20}$. The auxiliary subroutine DBESPQ has no inherent accuracy
limitations.

\begin{quote}Table 2. Maximum errors found in indicated regions for SBESYN.
Relative error is shown above the diagonal and absolute error below. Error
is shown as a multiple of the machine precision, $\approx 1.19
\times 10^{-7}$ for these tests.
\end{quote}\vspace{10pt}

\begin{picture}(208, 160)(-36, -20)
\put(-30, 75){$\nu$}
\multiput(0, 0)(0, 25){7}{\line(1, 0){180}}
\put(0, 0){\line(0, 1){150}}
\put(30, 0){\line(0, 1){125}}
\multiput(60, 0)(30, 0){5}{\line(0, 1){150}}
\put(-2, -10){0}
\put(28, -10){2}
\put(58, -10){5}
\put(85, -10){10}
\put(115, -10){20}
\put(144, -10){50}
\put(170, -10){100}
\put(-24, -10){\makebox(20, 20)[r]{0}}
\put(-24, 15){\makebox(20, 20)[r]{2}}
\put(-24, 40){\makebox(20, 20)[r]{5}}
\put(-24, 65){\makebox(20, 20)[r]{10}}
\put(-24, 90){\makebox(20, 20)[r]{20}}
\put(-24, 115){\makebox(20, 20)[r]{50}}
\put(-24, 140){\makebox(20, 20)[r]{100}}
\put(0, 0){\line (6, 5){180}}
\put(90, -20){$x$}
\put(0, 125){\makebox(60, 25){\small OVERFLOW}}
\put(0, 100){\makebox(30, 25){44}}
\put(0, 75){\makebox(30, 25){24}}
\put(0, 50) {\makebox(30, 25){8}}
\put(0, 25) {\makebox(30, 25){9}}
\put(0, 0)    {\makebox(30, 25){~\raisebox{5pt}{12} \hfill
\raisebox{-5pt}{28}~}}
\put(30, 100){\makebox(30, 25){84}}
\put(30, 75){\makebox(30, 25){25}}
\put(30, 50) {\makebox(30, 25){9}}
\put(30, 25) {\makebox(30, 25){~\raisebox{5pt}{9} \hfill
\raisebox{-5pt}{14}~}}
\put(30, 0)    {\makebox(30, 25){15}}
\put(60, 125){\makebox(30, 25){162}}
\put(60, 100){\makebox(30, 25){128}}
\put(60, 75){\makebox(30, 25){27}}
\put(60, 50){\makebox(30, 25){~\raisebox{5pt}{9} \hfill
\raisebox{-5pt}{9}~}}
\put(60, 25) {\makebox(30, 25){15}}
\put(60, 0) {\makebox(30, 25){10}}
\put(90, 125){\makebox(30, 25){286}}
\put(90, 100){\makebox(30, 25){143}}
\put(90, 75){\makebox(30, 25){~\raisebox{5pt}{29} \hfill
\raisebox{-5pt}{4}~}}
\put(90, 50){\makebox(30, 25){2}}
\put(90, 25) {\makebox(30, 25){1}}
\put(90, 0) {\makebox(30, 25){1}}
\put(120, 125){\makebox(30, 25){585}}
\put(120, 100){\makebox(30, 25){~\raisebox{7pt}{153}
\hspace{-4pt}\raisebox{-5pt}{19}\hspace{2pt}~}}
\put(120, 75){\makebox(30, 25){3}}
\put(120, 50){\makebox(30, 25){2}}
\put(120, 25) {\makebox(30, 25){2}}
\put(120, 0) {\makebox(30, 25){2}}
\put(150, 125){\makebox(30, 25){~\raisebox{7pt}{659}
\hspace{-4pt}\raisebox{-5pt}{68}\hspace{2pt}~}}
\put(150, 100){\makebox(30, 25){21}}
\put(150, 75){\makebox(30, 25){3}}
\put(150, 50){\makebox(30, 25){3}}
\put(150, 25) {\makebox(30, 25){3}}
\put(150, 0) {\makebox(30, 25){3}}
\end{picture}

\begin{center}
\centerline{Table 3. Single precision Wronskian test.}
\centerline{Tabulated value is $z(\nu ,x)/\text{R1MACH}(3)$}
\centerline{where R1MACH(3) $\approx 5.96 \times 10^{-8}.$}\vspace{-5pt}
\begin{tabular}{r|rrr}
\multicolumn{1}{c}{$\nu $} & $x \Rightarrow $ 5.1 & 15.3 & 30.6\\\hline
30.6 & 6.2 & 24.6 & 3.5\\
15.3 & 5.9 & 5.9 & 0.2\\
5.1 & 1.3 & 0.7 & 3.5\\
\end{tabular}\vspace{10pt}

\centerline{Table 4. Double precision Wronskian test.}
\centerline{Tabulated value is $z(\nu ,x)/\text{D1MACH}(3)$}
\centerline{where D1MACH(3) $\approx 1.11 \times 10^{-16}.$}\vspace{-5pt}
\begin{tabular}{r|rrr}
\multicolumn{1}{c}{$\nu $} & $x \Rightarrow $ 5.1 & 15.3 & 30.6\\\hline
30.6 & 32.2 & 17.2 & 16.0\\
15.3 & 3.9 & 5.8 & 0.4\\
5.1 & 1.0 & 1.8 & 0.1
\end{tabular}
\end{center}
\nocite{Olver:1972}
\nocite{Amos:1977:CSI}
\bibliography{math77}
\bibliographystyle{math77}

\subsection{Error Procedures and Restrictions}

These subroutines require $x \geq 0$, ALPHA $\geq 0$, and NUM $\geq 1$.
Violation of any of these conditions causes an error message and an
immediate return.

The subroutines attempt to anticipate and avoid overflow conditions.
Intermediate overflows are avoided by dynamic rescaling. If a final value of
Y would be beyond the overflow limit the value is set to $-\Omega /2$ and
an error message is issued. It is assumed that the host
system will set underflows to zero. No messages are issued for underflow.

If $x > (16\rho )^{-1}$ an error message is issued
since no accuracy can be obtained.

Subroutines SBESYN and DBESYN each contain an internal array AJ() to hold
values of $J_\nu (x)$ needed to compute $Y_\nu (x)$. The size requirement of
this array varies with the machine precision and is about $3(-\log _{10}
\rho ) + 3$. For example, for precisions of $10^{-10}$, $10^{-20}$,
and $10^{-30}$ the required size is 33, 63, and~95. The array is nominally
dimensioned~95 to handle all anticipated computers. An error message will be
issued in the unlikely event that a larger dimension is needed.

Error messages are issued by the error message processor of
Chapter~19.2.

The user should be aware that these subroutines require a substantial amount
of execution time, generally increasing linearly with the sum, ALPHA$+\text{%
NUM}.$

\subsection{Supporting Information}

The source language for these subroutines is ANSI Fortran 77.

Original subroutines SBJNU, SBYNU, DBJNU, DBYNU, BESJ, and BESY were
designed and programmed by W. V. Snyder and E. W. Ng, JPL, 1973, with
modifications by S.\ Singletary in 1974. The present subroutines are
modifications of the earlier subroutines to improve portability and
accuracy, avoid overflows, and conform to Fortran~77. These
subroutines were produced in 1984 by C. L. Lawson and S. Y. Chiu in
consultation with Snyder and Ng.

\begin{tabular}{@{\bf}l@{\hspace{5pt}}l}
\bf Entry & \hspace{.35in} {\bf Required Files}\vspace{2pt} \\
DBESJN & \parbox[t]{2.7in}{\hyphenpenalty10000 \raggedright
AMACH, DBESJN, DBESPQ, DERM1, DERV1, DGAMMA, ERFIN, ERMSG,
 IERV1\rule[-5pt]{0pt}{8pt}}\\
DBESYN & \parbox[t]{2.7in}{\hyphenpenalty10000 \raggedright
AMACH, DBESPQ, DBESYN, DERM1, DERV1, DGAMMA, DLGAMA, ERFIN,
ERMOR, ERMSG, IERV1\rule[-5pt]{0pt}{8pt}}\\
SBESJN & \parbox[t]{2.7in}{\hyphenpenalty10000 \raggedright
AMACH, ERFIN, ERMSG, IERV1, SBESJN, SBESPQ, SERM1, SERV1,
SGAMMA\rule[-5pt]{0pt}{8pt}}\\
SBESYN & \parbox[t]{2.7in}{\hyphenpenalty10000 \raggedright
AMACH, ERFIN, ERMOR, ERMSG, IERV1, SBESPQ, SBESYN, SERM1,
SERV1, SGAMMA, SLGAMA\rule[-5pt]{0pt}{8pt}}\\
\end{tabular}

\begcodenp
\lstset{language=[77]Fortran,showstringspaces=false}
\lstset{xleftmargin=.8in}

\centerline{\bf \large DRSBESJN}\vspace{10pt}
\lstinputlisting{\codeloc{sbesjn}}

\vspace{30pt}\centerline{\bf \large ODSBESJN}\vspace{10pt}
\lstset{language={}}
\lstinputlisting{\outputloc{sbesjn}}
\closegraphsfile
\end{document}


\section{The \equal and \mismatch algorithms}
\Label{sec:equal}
\Label{sec:mismatch}

The algorithms \equal \cite[\S 28.5.11]{cxx-17-draft}
and \mismatch \cite[\S 28.5.10]{cxx-17-draft}
of the \cxx Standard Library compare two generic sequences.
For our purposes we have modified the generic implementation
to that of an array of type \valuetype.
The signatures read

\begin{lstlisting}[style = acsl-block]

  bool       equal(const value_type* a, size_type n, const value_type* b);

  size_type  mismatch(const value_type* a, size_type n, const value_type* b);
\end{lstlisting}

The function \equal returns~\inl{true} if and only if
\inl{a[i] == b[i]} holds for each \inl{0 <= i < n}.
Otherwise,~\equal returns~\inl{false}.

The \mismatch algorithm is slightly more general than the negation of \equal:
it returns the smallest index where the two ranges~\inl{a} and~\inl{b} differ.
If no such index exists, that is, if both ranges are equal, then \mismatch
returns the (common) length~\inl{n} of the two ranges.

\subsection{The \Equal predicate}

The fact that two arrays \inl{a[0]..a[n-1]}
and \inl{b[0]..b[n-1]} are equal when compared element by element,
is a property we might need again in other specifications, as it
describes a very basic property.

The motto \emph{don't repeat yourself} is not just good programming
practice.\footnote{
    Compare \url{http://en.wikipedia.org/wiki/Don't_repeat_yourself}
}
It is also true for concise and easy to understand specifications.
We will therefore introduce specification elements that we can apply to
the \equal algorithm as well as to other specifications and
implementations with the described property.

We start with introducing several \emph{overloaded} versions
of the predicate~\logicref{Equal}.

\input{Listings/Equal.acsl.tex}

The letters \inl{K} and \inl{L} in the definition of \Equal
are so-called  \emph{labels}\footnote{
    Labels are used in \isoc to name the target of the \emph{goto}
    jump statement.
}
that refer to program states in which the ranges~\inl{a[..]} and~\inl{b[..]} are evaluated.
\framac defines several standard labels, e.g.\xspace \inl{Old}
and \inl{Post},
a programmer can use to refer to the pre-state or post-state,
respectively, of a function.
For more details on labels we refer to the \acsl
specification \cite[\S 2.6.9]{ACSLSpec}.

\subsection{Formal specification of \equal and \mismatch}

Using predicate \logicref{Equal} we can formulate the specification of \specref{equal}
using the predefined label~\inl{Here}.
When used in an \inl{ensures} clause, the label~\inl{Here} refers to the post-state of a function.
Note that the equivalence is needed in the ensures clause.
Putting an equality instead is not legal in ACSL,
because \Equal is a predicate, not a function.

\input{Listings/equal.h.tex}

The formal specification of \specref{mismatch}
is more complex than that of \specref{equal} because the return value of mismatch
provides more information than just reporting whether the two arrays are equal.

\input{Listings/mismatch.h.tex}

On the other hand, the specification is conceptually quite similar to that of \specref{findii}.
%
While \findii returns the smallest index~\inl{i} where \inl{a[i] == v} holds,
\mismatch finds the smallest index \inl{a[i] != b[i]}.
Note in particular the use of \Equal in the specification of \mismatch.
As in the specification of \findii
the completeness and disjointness of \mismatch's behaviors is quite obvious,
because the \inl{assumes} clauses of
\inl{all_equal} and \inl{some_not_equal} are negations of each other.

%\clearpage

\subsection{Implementation of \equal and \mismatch}

The implementation of \implref{equal} consists of a simple call of \mismatch.

\input{Listings/equal.c.tex}

The implementation of \implref{mismatch}
has been enriched with some loop annotations to support the deductive verification.

\input{Listings/mismatch.c.tex}

We use again the predicate \logicref{Equal}
in order to express that all indices~\inl{k} that are less than the
current index~\inl{i}
satisfy the condition \inl{a[k] == b[k]}.
This is necessary to prove that \mismatch indeed returns the smallest index
where the two ranges differ.

\clearpage


\documentclass[]{article}
\usepackage[left=2cm,top=2cm,right=2cm]{geometry}
\usepackage{url}
\begin{document}

\title{Theory used by libgfshare}
\author{Simon McVittie}
\date{23rd April 2006}
\maketitle

\section{Introduction}

libgfshare implements Shamir secret sharing [SHAMIR] over the field $GF(2^8)$,
instead of $GF(p)$ for a prime $p$ as suggested by Shamir's paper.
This document aims to prove the security and integrity of this scheme.

Note that while I believe this document to be correct, I accept no
responsibility for loss or damage caused by relying on the correctness
of my proof.

\section{Definitions}

Let $F$ be a field with multiplicative identity 1 and additive identity 0.

If $A = \{(a_1, b_1), \cdots, (a_n, b_n)\}$, with the $a_i$ distinct nonzero
elements of F and the $b_i$ elements of $F$, indexed by $I = \{1,\cdots,n\}$,
then define

\[
        P_A(x) = \sum_{j\in I} {b_j \prod_{k\in I, k\neq j} {(x-a_k)(a_j-a_k)^{-1}}}
\]

a polynomial of degree at most $n-1$. (By distinctness of the $a_i$, the
inverses required exist.) This is the Lagrange interpolating polynomial
for the points in $A$.

\section{Lemma 1}

Let $a_1,\cdots,a_t\in F$ be distinct and nonzero; let
$b_1,\cdots,b_{t-1},c\in F$ be arbitrary. Then there exists $b_t\in F$
such that if $A = \{(a_1, b_1), \cdots, (a_t, b_t)\}$ then $P_A(0) = c$.

\subsection{Proof}

Let $I = \{1, \cdots, t\}$. We have

\[
P_A(0) = \sum_{j\in I} {b_j \prod_{k\in I, k\neq j}{-a_k(a_j-a_k)^{-1}}}
= \sum_{j\in I} {y_j \prod_{k\in I, k\neq j}{a_k(a_k-a_j)^{-1}}}
\]

Let

\[
b_t = \left[c + \sum_{j\in I, j\neq t}{b_j\prod_{k\in I,k\neq j}{a_k(a_j-a_k)^{-1}}}\right]
        \left[\prod_{k\in I,k\neq t}{a_k^{-1}(a_k-a_t)}\right]
\]

Then

\[
P_A(0) = \sum_{j\in I, j\neq t} {b_j \prod_{k\in I, k\neq j}{a_k(a_k-a_j)^{-1}}} + b_t \prod_{k\in I, k\neq t}{a_k(a_k-a_t)^{-1}}
\]\[
= \sum_{j\in I, j\neq t} {b_j \prod_{k\in I, k\neq j}{a_k(a_k-a_j)^{-1}}} - \sum_{j\in I, j\neq t} {b_j \prod_{k\in I, k\neq j}{a_k(a_k-a_j)^{-1}}} + c
\]\[
= c
\]

as required.

\section{Lemma 2}

For any $x_1,\cdots,x_t$ distinct and nonzero elements of $F$, and any
$y_1,\cdots,y_t,u$ arbitrary elements of $F$, let

\[X = \left\{(x_1,y_1),\cdots,(x_t,y_t)\right\}\]

and

\[U = \left\{(x_1,y_1),\cdots,(x_{t-1},y_{t-1}),(u,P_X(u))\right\}\]

Then $P_X = P_U, i.e. P_X(x) = P_U(x)$ for all $x\in F$.

\subsection{Proof}

Let $S_{a,b} = \left\{(x_1,y_1),\cdots,(x_{t-1},y_{t-1}),(a,b)\right\}$.
Then

\[
P_{S_{a,b}}(x) = \sum_{j<t} y_j (x-a)(x_j-a)^{-1}
        \prod_{k\ne j,k<t}(x-x_k)(x_j-x_k)^{-1}
        + b\prod_{k<t}(x-x_k)(a-x_k)^{-1}
\]

Hence if we let $d_{i,j} = x_i - x_j$ and $e_i = u - x_i$ (both of which
are necessarily nonzero, by distinctness of the $x_i$ and $u$) we have

\[
P_X(u) = \sum_{j<t} y_j e_t d_{j,t}^{-1}
        \prod_{k\ne j,k<t}e_kd_{j,k}^{-1}
        + y_t\prod_{k<t}e_kd_{t,k}^{-1}
\]

and if we also let $f_i = x - x_i$,

\[
P_U(x) = \sum_{j<t} y_j (u-x)e_j^{-1} \prod_{k\ne j,k<t}f_k d_{j,k}^{-1}
    + P_X(u)\prod_{k<t} f_k e_k^{-1}
\]\[
P_U(x) = \sum_{j<t} y_j (u-x)e_j^{-1} \prod_{k\ne j,k<t}f_k d_{j,k}^{-1}
    + \left\{\prod_{k<t} f_k e_k^{-1}\right\}\left\{
        \sum_{j<t} y_j e_t d_{j,t}^{-1}\prod_{l\ne j,l<t}e_kd_{j,l}^{-1}
        + y_t\prod_{l<t}e_ld_{t,l}^{-1}
    \right\}
\]

Expanding,

\[
\begin{array}{rcl}
P_U(x) & = & \sum_{j<t}y_j(u-x)e_j^{-1}\left\{\prod_{k\ne j,k<t}f_kd_{j,k}^{-1}\right\} \\
& & + \sum_{j<t}y_je_td_{j,t}^{-1}
        \left\{\prod_{l\ne j,l<t}e_kd_{j,l}^{-1}\right\}
        \left\{\prod_{k<t}f_ke_k^{-1}\right\} \\
& & + y_t\left\{\prod_{k<t}e_kd_{t,k}^{-1}f_ke_k^{-1}\right\}
\end{array}
\]

\[
P_U(x) = \sum_{j<t}y_j\left[
        (u-x)e_j^{-1}\left\{\prod_{k\ne j,k<t}f_kd_{j,k}^{-1}\right\}
        + e_td_{j,t}^{-1}f_je_j^{-1}\left\{
            \prod_{k\ne j,k<t}e_kd_{j,k}^{-1}f_ke_k^{-1}
        \right\}
    \right]
    + y_t\prod_{k<t}d_{t,k}^{-1}f_k
\]\[
= \sum_{j<t} \left[y_j \prod_{k\ne j,k<t}f_kd_{j,k}^{-1}\right]
        \left[(u-x)e_j^{-1} + e_te_j^{-1}d_{j,t}^{-1}f_j\right]
        + y_t\prod_{k<t}d_{t,k}^{-1}f_k
\]

Now

\[
(u-x)e_j^{-1} + e_te_j^{-1}d_{j,t}^{-1}f_j
    = (e_j^{-1}d_{j,t}^{-1})\left[(u-x)d_{j,t} + e_tf_j\right]
\]\[
    = (e_j^{-1}d_{j,t}^{-1})\left[(u-x)(x_j-x_t) + (u-x_t)(x-x_j)\right]
\]\[
    = (e_j^{-1}d_{j,t}^{-1})(x - x_t)(u - x_j)
\]\[
    = d_{j,t}^{-1}f_t
\]

Hence

\[
P_U(x)
= \sum_{j<t} \left[y_j \prod_{k\ne j,k<t}f_kd_{j,k}^{-1}\right]
        \left[f_td_{j,t}^{-1}\right]
        + y_t\prod_{k<t}d_{t,k}^{-1}f_k = P_X(x)
\]

as required.

\section{Construction}

Let $s$ be the number of ``shares'' and $t$ be the required threshold
to recover the shared secret (i.e. we construct a ``$t$ of $s$'' share).

Given a secret $f\in F$ we may construct a Lagrange interpolating
polynomial $P_X$ of degree no more than $t-1$, with $P_X(0) = f$, as
follows:

- choose distinct nonzero $x_1,\cdots,x_s \in F$

- choose arbitrary (and unpredictable) $y_1,\cdots,y_{t-1} \in F$

- use Lemma 1 to select $y_t$ such that $X = \{(x_1,y_1),\cdots,(x_t,y_t)\}$
  has the desired intercept $f$

To obtain additional shares, calculate
$y_{t+1} = P_X(x_{t+1}),\cdots,y_s=P_X(x_s)$.

\section{Alternate construction, as used in libgfshare}

In libgfshare the construction used is as follows:

- construct a polynomial $P$ by choosing arbitrary and unpredictable
  coefficients of $x,\cdots,x^{t-1}$ from $F$, and setting the coefficient
  of $x^0$ to $f$: this therefore has the desired intercept $f$

- choose distinct nonzero $x_1,\cdots,x_s \in F$ and evaluate
  $y_1 = P(x_1),\cdots,y_s = P(x_s)$

\subsection{Proof of equivalence in a finite field $F$}

Suppose $F$ is finite, as is the case in libgfshare, and that in each
construction, arbitrary choices are made from among all possible
values in $F$.

In the alternate construction, given $x_1,\cdots,x_t,f$ we choose a
polynomial $P(x) = f+m_1x+\cdots+m_{t-1}x^{t-1}$
by choosing arbitrary coefficients $m_1,\cdots,m_{t-1}\in F$, i.e.
choosing arbitrarily from among the $\left|F\right|^{t-1}$ distinct
polynomials of degree no more than $t-1$ with intercept $f$.

In the first construction, given $x_1,\cdots,x_t,f$ we obtain a polynomial
by choosing arbitrary $y_1,\cdots,y_{t-1}\in F$. The polynomials chosen
are necessarily distinct since no polynomial can pass through both $(x_i, p)$
and $(x_i, q)$ for any $p \ne q$, so by choosing each $y_i$ from among the
$\left|F\right|$ elements of $F$, we choose arbitrarily from a set of
$\left|F\right|^{t-1}$ distinct polynomials whose intercepts are all $f$.

Since there are only $\left|F\right|^{t-1}$ such polynomials, each
construction chooses arbitrarily from among the same set, and by the
pigeonhole principle there exists a bijective mapping between sets of
arbitrary $y$ values in the first construction and sets of arbitrary
coefficients in the second.

\section{Theorem: With at least $t$ pieces the secret is recoverable}

Let $B \subset\left\{(x_1,y_1),\cdots,(x_s,y_s)\right\}$ with $|B| = t$.
Then $P_B(0) = c$.

Further, if $B^\prime \subset\left\{(x_1,y_1),\cdots,(x_s,y_s)\right\}$
with $|B^\prime| > t$, then for every subset $B$ of $B^\prime$ with
$|B| = t$, $P_B(0) = f$.

\subsection{Proof}

The second part is trivially implied by the first.

Recall that $X = \left\{(x_1,y_1),\cdots,(x_t,y_t)\right\}$ and that
$P_X(0) = f$. If $B = X$ the result is true. If not, repeatedly apply
Lemma 2 to replace an element of $X$ not in $B$ with an element of $B$ not
in $X$, preserving the value of $P(0)$.

\section{Theorem: With fewer than $t$ pieces no information is gained}

Let $C \subset\left\{(x_1,y_1),\cdots,(x_s,y_s)\right\}$ with $|C|< t$.
Then for each $d\in F$, there exists $D\supset C$, $|D| = t$, such that
$d = P_D(0)$.

(In other words, any $d\in F$ remains a possible value for the secret, so
an attacker with fewer than $t$ shares has gained no information.)

\subsection{Proof}

Let $a_i$, $b_i$ be such that $C = \left\{(a_1,b_1),\cdots,(a_n,b_n)\right\}$,
some $n < t$. Choose arbitrary $a_{n+1},\cdots,a_{t}$ and arbitrary
$b_{n+1},\cdots,b_{t-1}$. Let $b_t$ be chosen by applying Lemma 1
with $c := d$. Then by choice of $b_t$, $P_C(0) = d$ as required.

\section{Implementation in $GF(2^8)$}

The program \texttt{test\_gfshare\_isfield}, compiled and run by
\texttt{make check}, demonstrates that the calculations done by
libgfshare are indeed performed in a field.

\section{Attacks not addressed}

This document has not addressed the following:

- Attacks based on the use of a predictable or partially predictable
  pseudorandom number generator might be possible.

- In the implementation used in libgfshare, the field $F$ is the field
  of byte values, with addition being bitwise exclusive-or, and multiplication
  as usual; each byte of the secret is shared separately by applying this
  algorithm separately. This means that when a secret file is shared,
  the length in bytes of each share equals the length in bytes of the
  secret. If the length of the secret is itself secret, it should be
  padded to some standard length before sharing.

\section{References}

[SHAMIR] Adi Shamir, "How to share a secret", Communications of the ACM, 22(1), pp612--613, 1979. Available at \url{http://www.cs.tau.ac.il/~bchor/Shamir.html}

\section{Copyright and disclaimer}

Copyright 2006 Simon McVittie, \url{http://smcv.pseudorandom.co.uk/}

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

\end{document}


\vsssub
\subsubsection{~$S_{\mathrm{in}} + S_{\mathrm{ds}}$: Saturation-based dissipation} \label{sec:ST4}
\vsssub

\opthead{ST4}{\ws}{F. Ardhuin, J.-F. Filipot \& L. Romero}

\noindent
This family of parameterizations uses a positive part of the wind input taken
from WAM cycle 4 with an ad hoc reduction of $u_\star$, implemented in
order to allow a balance with a saturation-based dissipation that uses different options for
a cumulative term. There are three main options for defining the saturation and the cumulative term. Chosing one or the other is done with the  {\F SDSBCHOICE} parameter, with  {\F SDSBCHOICE=1} for \cite{art:Aea10},  {\F SDSBCHOICE=2} for \cite{Filipot&Ardhuin2012}, and {\F SDSBCHOICE=3} for \cite{Romero2019}. That last options uses a saturation that is defined from the local spectral density, and thus gives zero dissipation for directions where the threshold is not reached, leading to much broader directional spectra. Also the stronger bimodality is achieved by having a strong modulation effect as a cumulative term.

Many other adjustments can be made by changing the namelist parameters. A few successful combinations
are given by tables \ref{tab:ST4_parSIN} and \ref{tab:ST4_parSDS}, with results described by \citep{art:RA13,art:SAG16}.
Further calibration to any particular wind field should be done for best performance. Guidance for this is given by \cite{Stopa2018}.
%We also note that the particular
%set of parameters T400 corresponds to setting IPHYS=1 in the ECWAM code cycle 45R2, with a few differences
%related to the fact that precomputed stress tables have now been removed from ECWAM.

\vsssub
\textbf{Wind input and swell dissipation}
\vsssub

The reduction of $u_\star$ in
eq. (\ref{eq:SinWAM4}) is obtained by replacing it with $u_\star '(k)$ defined for each
frequency as

\begin{equation}
\left(u_\star '\right)^2=\left|u_\star^2 \left(\cos \theta_u, \sin
\theta_u \right) - \left|s_u\right| \int_0^k \int_0^{2 \pi}
\frac{S_{in}\left(k',\theta \right)}{C}  \left(\cos \theta, \sin
\theta \right)  {\mathrm d} k' \mathrm d
\theta,\label{ustarp}\right|
\end{equation}

\noindent
where the sheltering coefficient $\left|s_u\right|\sim 1$ can be used to tune
the stresses at high winds, which would be largely overestimated for
$s_u=0$. For $s_u > 0$ this sheltering is also applied within the diagnostic
tail in eq. (\ref{eq:tauhfint}), which requires the estimation of a
3-dimensional look-up table for the high frequency stress, the third parameter
being the energy level of the tail.

The {\code STAB3} switch, described above for use with {\code ST3}, may also be used with {\code ST4}. If {\code STAB3} is used, the air-sea  temperature differences should be provided by the user, e.g. using {\file ww3\_prep}.

The swell dissipation parameterization of \cite{art:ACC09} is activated by
setting $s_1$ to a non-zero integer value, and is given by a combination of
the viscous boundary layer value,

\begin{equation}
\cS_{\mathrm{out,vis}}\left(k,\theta\right) = - s_5 \frac{\rho_a}{\rho_w}\left\{ 2 k \sqrt{2
\nu \sigma}\right\}  N \left(k,\theta\right) , \label{eq:Dore}
\end{equation}

\noindent
with the turbulent boundary layer expression
\begin{equation}
\cS_{\mathrm{out,tur}} \left(k,\theta\right) = - \frac{\rho_a}{\rho_w}\left\{  16 f_e
\sigma^2 u_{\mathrm{orb},s} / g \right\}
 N\left(k,\theta\right),  \label{eq:swell_turb}
\end{equation}

\noindent
giving the full term
\begin{equation}
\cS_{\mathrm{out}} \left(k,\theta\right) = r_{vis} \cS_{\mathrm{out,vis}}\left(k,\theta\right)  +
 r_{tur} \cS_{\mathrm{out,tur}}\left(k,\theta\right),
 \label{eq:swell_comb}
\end{equation}

\noindent
where the two weights $ r_{\mathrm{vis}} $ and $r_{\mathrm{tur}}$ are defined from
a modified  air-sea boundary layer significant Reynolds number $\mathrm{Re} = 2
u_{\mathrm{orb},s} H_s / \nu_{a}$

\begin{eqnarray}
 r_{\mathrm{vis}} &=& 0.5 (1- \tanh((\mathrm{Re}-\mathrm{Re}_{c})/s_7), \\
 r_{\mathrm{tur}}&=& 0.5 (1+ \tanh((\mathrm{Re}-\mathrm{Re}_{c})/s_7) .
\end{eqnarray}
The significant surface orbital velocity is defined by
\begin{equation} u_{\mathrm{orb},s} = 2 \left [  \int \!\!\!\! \int
      \sigma^3 \: N(k,\theta) \: dk d\theta \right ] ^{1/2}
      \: . \label{eq:ub_orbs} \end{equation}

\noindent
The first equation (\ref{eq:Dore}) is the linear viscous decay by
\cite{art:Dore78}, with $\nu_a$ the air viscosity and $s_5$ is an $O(1)$
tuning parameter. A few tests have indicated that a threshold Re$_{c}=2 \times
10^5 \times (4~\mathrm{m}/H_s)^{(1-s_6)}$ provides reasonable result with
$s_6=0$, although it may also be a function of the wind speed, and we have no
explanation for the dependence on $H_s$.  With $s_6=1$, a constant threshold
close to $2 \times 10^5$ provides similar -- but less accurate -- results.

\begin{landscape}
\begin{table}
\begin{center}
%\begin{tabular}{|l|c|c|c|c|c|c|c|c|} \hline \hline
%Par.         &  WWATCH var.       & namelist & T471    & T471f       & T400/$I_{\mathrm{phys}}=1$    & T405          & T500         & T601     \\
%\hline
%  $z_u$ &  ZWND                       & SIN4 & 10.0    & 10.0        & 10.0           & 10.0          & 10.0         & 10.0        \\
%  $\alpha_0$ &  ALPHA0                & SIN4 & 0.0095  & 0.0095      & \textbf{0.0062}& 0.0095        &  0.0095      & 0.0095      \\
%  $\beta_{\mathrm{max}}$ & BETAMAX    & SIN4 & 1.43    &\textbf{1.33}&\textbf{1.42}   & \textbf{1.55} &\textbf{1.52} & \textbf{2.0}\\
%  $p_{\mathrm{in}}$ &  SINTHP         & SIN4 & 2       & 2           & 2              & 2             &  2           & \textbf{1}  \\
%  $z_\alpha$ &  ZALP                  & SIN4 & 0.006   & 0.006       & 0.008          & 0.006         &0.006         & 0.006       \\
%  $s_u$ &  TAUWSHELTER                & SIN4 & 0.3     & 0.3         & \textbf{0.25}  & \textbf{0.0}  &\textbf{1.0}  & \textbf{0.5}\\
%  $s_1$ &  SWELLF                     & SIN4 & 0.66    & 0.66        & 0.66           & 0.8           &  0.8         & 0.66        \\
%  $s_2$ &  SWELLF2                    & SIN4 & -0.018  & -0.018      &-0.018          & -0.018        &  -0.018      &  -0.018     \\
%  $s_3$ &  SWELLF3                    & SIN4 &  0.022  &  0.022      & 0.022          &\textbf{0.015} &\textbf{0.015}&  0.022      \\
%  $\mathrm{Re}_c$ &  SWELLF4          & SIN4 &$1.5\X^5$& $1.5\X^5$   & $1.5\X^5$      &$\mathbf{10^5}$&$\mathbf{10^5}$&  $1.5\X^5$ \\
%  $s_5$ &  SWELLF5                    & SIN4 & 1.2     & 1.2         & 1.2            & 1.2           &  1.2         & 1.2         \\
%  $s_6$ &  SWELLF6                    & SIN4 & 0.      & 0.          & \textbf{1.0}   & 0.            & 0.           & 0.          \\
%  $s_7$ &  SWELLF7                    & SIN4 &3.6$\X^5$&3.6$\X^5$    & 3.6$\X^5$      &\textbf{0.0}   &\textbf{0.0}  & 3.6$\X^5$   \\
%  $z_r$ &  Z0RAT                      & SIN4 & 0.04    & 0.04        & 0.04           & 0.04          &  0.04        &   0.04      \\
%  $z_{0,\max}$ &  Z0MAX               & SIN4 & 1.002   & 1.002       & 1.002          &\textbf{0.002} &  1.002       &  1.002      \\
%\hline
%\end{tabular}
\begin{tabular}{|l|c|c|c|c|c|c|c|} \hline \hline
Par.         &  WWATCH var.       & namelist & T471    & T471f       & T405          & T500         & T601     \\
\hline
  $z_u$ &  ZWND                       & SIN4 & 10.0    & 10.0        & 10.0          & 10.0         & 10.0        \\
  $\alpha_0$ &  ALPHA0                & SIN4 & 0.0095  & 0.0095      & 0.0095        &  0.0095      & 0.0095      \\
  $\beta_{\mathrm{max}}$ & BETAMAX    & SIN4 & 1.43    &\textbf{1.33}& \textbf{1.55} &\textbf{1.52} & \textbf{2.0}\\
  $p_{\mathrm{in}}$ &  SINTHP         & SIN4 & 2       & 2           & 2             &  2           & \textbf{1}  \\
  $z_\alpha$ &  ZALP                  & SIN4 & 0.006   & 0.006       & 0.006         &0.006         & 0.006       \\
  $s_u$ &  TAUWSHELTER                & SIN4 & 0.3     & 0.3         & \textbf{0.0}  &\textbf{1.0}  & \textbf{0.5}\\
  $s_1$ &  SWELLF                     & SIN4 & 0.66    & 0.66        & 0.8           &  0.8         & 0.66        \\
  $s_2$ &  SWELLF2                    & SIN4 & -0.018  & -0.018      & -0.018        &  -0.018      &  -0.018     \\
  $s_3$ &  SWELLF3                    & SIN4 &  0.022  &  0.022      &\textbf{0.015} &\textbf{0.015}&  0.022      \\
  $\mathrm{Re}_c$ &  SWELLF4          & SIN4 &$1.5\X^5$& $1.5\X^5$   &$\mathbf{10^5}$&$\mathbf{10^5}$&  $1.5\X^5$ \\
  $s_5$ &  SWELLF5                    & SIN4 & 1.2     & 1.2         & 1.2           &  1.2         & 1.2         \\
  $s_6$ &  SWELLF6                    & SIN4 & 0.      & 0.          & 0.            & 0.           & 0.          \\
  $s_7$ &  SWELLF7                    & SIN4 &3.6$\X^5$&3.6$\X^5$    &\textbf{0.0}   &\textbf{0.0}  & 3.6$\X^5$   \\
  $z_r$ &  Z0RAT                      & SIN4 & 0.04    & 0.04        & 0.04          &  0.04        &   0.04      \\
  $z_{0,\max}$ &  Z0MAX               & SIN4 & 1.002   & 1.002       &\textbf{0.002} &  1.002       &  1.002      \\
\hline
\end{tabular}

 \end{center}
\caption{Parameter values for T471, T471f, T405, T500, and T601 source
term parameterizations that can be reset via the {\F SIN4} namelist.
Please note that the names of the variables only apply to the namelists. In the
source term module the names are slightly different, with a doubled first
letter, in order to differentiate the variables from the pointers to these
variables, and the SWELLFx are combined in one array SSWELLF. Values highlighted in bold are
different from the default values set by ww3\_grid.} \label{tab:ST4_parSIN}
\end{table}
\end{landscape}

TEST471 generally provides the best results at global scale when using ECMWF winds,
with the only serious problem being a low bias for $H_s > 8$~m.  TEST451f
corresponds to a retuning for CSFR wind reanalysis from NCEP/NCAR
\citep{art:CFSRR10}, and has almost no bias all the way to $H_s =
15$~m. Simulations and papers prepared before March 2012, used slightly
different values, {\it e.g.} TEST441 and TEST441f can be recovered by setting SWELLF7 to 0, and
TEST471 also used $s_u=1$ and a few other adjustements (see manual of version 4.18).
TEST405 is slightly superior for short fetches, and TEST500 is intermediate in
terms of quality but it also includes depth-induced breaking in the same
formulation, and thus may be more appropriate for depth-limited conditions.

Eq. (\ref{eq:swell_turb}) is a parameterization for the
nonlinear turbulent decay. When comparing model results to observations, it
was found that the model tended to underestimate large swells and overestimate
small swells, with regional biases. This defect is likely due, in part, to
errors in the generation or non-linear evolution of theses swells. However, it
was chosen to adjust $f_e$ as a function of the wind speed and direction,

\begin{equation}
f_e = s_1 f_{e,GM} + \left[\left|s_3\right| + s_2 \cos
(\theta-\theta_u)\right]u_\star / u_{\mathrm{orb}},\label{fevar}
\end{equation}

\noindent
where $f_{e,GM}$ is the friction factor given by Grant and Madsen's
(1979)\nocite{art:GM79} theory for rough oscillatory boundary layers without a
mean flow, using a roughness length adjusted to $r_z$ times the roughness for
the wind $z_1$. The coefficient $s_1$ is an $O(1)$ tuning parameter, and the
coefficients $s_2$ and $s_3$ are two other adjustable parameters for the
effect of the wind on the oscillatory air-sea boundary layer. When $s_2 < 0$,
wind opposing swells are more dissipated than following swells. Further, if
$s_3 > 0$, $\cS_{out}$ is applied to the entire spectrum and not just the
swell.

\vsssub
\textbf{Wave breaking and ocean turbulence effects}
\vsssub

The dissipation term is parameterized from the wave spectrum saturation, following the general ideas of \cite{art:Phi85}.
%which were initially explored in a numerical modeling framework by \cite{art:AB03}.
The saturation spectrum is
\begin{equation}
B\left(k,\theta\right)= \sigma k^3  N(k,\theta) \label{defB},
\end{equation}
and corresponds to a dimensionless form of the surface elevation spectrum. In general, going from the spectral space to the physical space requires
integrating the saturation over a finite spectral band in wavenumber and direction to compute the breaking probability
and then deconvolve this integral to obtain a spectral dissipation rate. Because such operations would be too time consuming we have
implemented three approaches. One uses on integration over directions only \citep{art:Aea10}, while the second uses an integration  over frequency
bands \citep{Filipot&Ardhuin2012}, and the last actually uses the local value of $B$ without integration at all. Using one or the other version activated by the namelist parameter {\F  SDSBCHOICE  }.

Because the directional wave spectra were too narrow when using a
saturation spectrum integrated over the full circle \citep{art:AL06},
\citet{art:Aea10} restricted over a sector of half-width $\Delta_\theta$,
\begin{equation}
B'\left(k,\theta\right)=
\int_{\theta-\Delta_\theta}^{\theta+\Delta_\theta} \sigma k^3 cos^{\mathrm{sB}}\left(\theta-
\theta^{\prime}\right) N(k,\theta^{\prime}) \mathrm d
\theta^{\prime} \label{defBofkprime}.
\end{equation}
As a result, a sea state with two systems of same energy but opposite
direction will typically produce less dissipation than a sea state with all
the energy radiated in the same direction.

Based on recent analysis by \cite{Guimaraes2018} and \cite{Peureux&al.2019}, this saturation is enhanced by a factor $M_L$ that represents
the effect of long waves on short waves
\begin{equation}
M_l(k,\theta)=1+M_\theta \sqrt{\mathrm{mss}(k,\theta)} + N_\theta \sqrt{\mathrm{nss}(k,\theta)} \label{defFACSAT}.
\end{equation}
where $M_\theta$ is twice the modulation transfer function for short wave steepness, with
$M_\theta=8$ when following the simplified theory by \cite{art:LHS60} and using the root mean square enhancement of $B$ over a
long wave cycle. $N_\theta$ is an additional straining factor due to the instability of the wave action envelope of short waves
propagating in the direction close to that of the long wave \citep{Peureux&al.2019}. The squared slopes $\mathrm{mss}(k,\theta)$ is
the mean square slope in direction $\theta$, wheras $\mathrm{nss}(k,\theta)$ is a slope of long waves propagating in a narrow window $\pm \delta_\theta$,
around the short wave direction $\theta$.

We finally define our dissipation term as the sum of the saturation-based term
and a cumulative breaking term $S_{\mathrm{bk,cu}}$,
\begin{eqnarray}
\cS_{ds}(k,\theta)& =&  \sigma
 \frac{C_{\mathrm{ds}}^{\mathrm{sat}}}{B^2_r} \left[ \delta_d
\max\left\{ M_l(k,\theta) B\left(k\right) -
B_r,0\right\}^2 \right.
\nonumber \\
  & & +  \left(1-\delta_d \right) \left. \max\left\{ M_L(k,\theta) B'\left(k,\theta \right)- B_r
 ,0\right\}^2\right]N(k,\theta)  \nonumber \\
 & & + \cS_{\mathrm{bk,cu}}(k,\theta) + \cS_{\mathrm{turb}}(k,\theta) \label{Sds_all}.
\end{eqnarray}
where
\begin{equation}
B\left(k \right)=\max\left\{B'(k,\theta), \theta \in [0,2
\pi[\right\} \label{defBof}.
\end{equation}
The combination of an isotropic part (the term that multiplies $ \delta_d$)
and a direction-dependent part (the term with $1-\delta_d$) was intended to
allow some control of the directional spread in resulting spectra.

The cumulative breaking term $\cS_{\mathrm{bk,cu}}$ represents the smoothing
of the surface by big breakers with celerity $C'$ that wipe out smaller waves
of phase speed $C$. Due to uncertainties in the estimation of this effect in
various observations, we use the theoretical model of
\cite{art:Aea09}. Briefly, the relative velocity of the crests is the norm of
the vector difference, $\Delta_C =\left|\mathbf{C}-\mathbf{C}'\right|$, and
the dissipation rate of short wave is simply the rate of passage of the large
breaker over short waves, i.e. the integral of $\Delta_C \Lambda(\mathbf{C})
d\mathbf{C}$, where $\Lambda (\mathbf{C}) d\mathbf{C}$ is the length of
breaking crests per unit surface that have velocity components between $C_x$
and $C_x+dC_x$, and between $C_y$ and $C_y+dC_y$ \citep{art:Phi85}.  Here
$\Lambda$ is inferred from breaking probabilities. Based on Banner et
al. (2000, figure 6, $b_T=22
\left(\varepsilon-0.055\right)^2$)\nocite{art:BBY00}, and taking their
saturation parameter $\varepsilon$ to be of the order of $1.6
\sqrt{B'(k,\theta)}$, the breaking probability of dominant waves is
approximately
\begin{equation}
P=56.8\left(\max\{\sqrt{B'(k,\theta)}-\sqrt{B'_r},0\}\right)^2.\label{PBanner}
\end{equation}
However, because they used a zero-crossing analysis, for a given wave scale,
there are many times when waves are not counted because the record is
dominated by another scale: in their analysis there is only one wave at any
given time.  This tends to overestimate the breaking probability by a factor
of 2 \citep{art:FAB10}, compared to the present approach in which it is
considered that several waves (of different scales) may be present at the same place and
time. This effect is corrected simply dividing $P$ by 2.

With this approach the spectral density of crest length (breaking or not) per
unit surface $l(\mathbf{k})$ such that $\int l(\mathbf{k}) \mathrm{d}k_x
\mathrm{d}k_y$, we take
\begin{equation}
l(\mathbf{k})= 1/(2\pi^2 k),
\end{equation}
and the spectral density of breaking crest length per unit surface is
$\Lambda(\mathbf{k})=l(\mathbf{k})P(\mathbf{k})$.

Finally the last option for the ST4 implementation of a saturation-based dissipation is as generalization
of the parameterization by \citet{Romero2019}, giving some flexibility in the definition of the modulation
term, this is activated by setting  {\F  SDSBCHOICE  = 3}. In this case the  breaking crest density for wavenumber vector
$\mathbf{k}$ is a function of the saturation only for the same wavenumber, $B(\mathbf{k})$, with no integration in direction
or frequency (which would be problematic if applied ot monochromatic wave spectra), but a strong modulation $M_L$  by long waves
and a wind-dependent correction $M_W$
\begin{equation}
\Lambda (\mathbf{k}) = \frac{1}{k} \exp \left(-\frac{B_{\mathbf{r}}}{M_l(\mathbf{k})  B(\mathbf{k})}\right) M_L(\mathbf{k}) M_W(k).
\end{equation}
where the wind factor is,
\begin{equation}
 M_W(k)=\left( 1+ D_W  \max(1,k/k_0) \right) / (1+D_W),
\end{equation}
where $k_0=g (3/ 28 u_\star)^2$, and $D_W$ was adjusted to 0.9 when using the DIA, and $D_W=2$ for the exact nonlinear interaction.
The long wave modulation is either applied to $B$ (if $N_\theta > 0$) and takes the form $ M_l(k,\theta)$ given above,
or, as done in \cite{Romero2019} the modulation is applied to  $\Lambda$ and takes the form,
\begin{equation}
 M_L(k,\theta)=\left( 1+ M_\Lambda \sqrt{\mathrm{mss}'(k,\theta)}  \right)^{1.5}.
\end{equation}
In that expression, the cumulated slope $\mathrm{mss}'$ is either $\mathrm{mss}(k,\theta)$ or, if $N_\theta=0$, it is forced to have a $\cos^2 (\theta-\theta_w)$ variation,
with $\theta_w$ the direction of the mean dominant waves (which is independant of $k$). In \cite{Romero2019} this strong $\cos^2$ directional dependency of $\Lambda$ is key for producing
strong bimodal spectra, and it may be a compensation for the isotropic dissipation rate. Indeed, the full source term for {\F  SDSBCHOICE  = 3} reads
\begin{eqnarray}
\cS_{ds}(k,\theta)=  \frac{C_{\mathrm{ds}}^{\mathrm{sat}} (\sqrt{B(k)}-\sqrt{B_T} )^2.5}{g^2} \Lambda (k,\theta) c^5 + \cS_{\mathrm{bk,cu}}(k,\theta) + \cS_{\mathrm{turb}}(k,\theta) \label{Sds_all}. \nonumber \\
\end{eqnarray}
where it should be noted that the saturation used in the dissipation rate $b=C_{\mathrm{ds}}^{\mathrm{sat}} (\sqrt{B(k)}-\sqrt{B_T} )^2.5/{g^2}$ is integrated over direcitons. and uses a true threshold $B_T$ that is different from the $B_r$ in the expression of $\Lambda$.
Also, the generalization of \cite{Romero2019} allows to use a modulation of $B$ or $\Lambda$ and offers different options for the directional distribution of this modulation. Also, this breaking term can be combined with the cumulative term of \cite{art:Aea10} and the wave-turbulence interaction term of \citet{art:AJ06}.

For all three choices of {\F SDSBCHOICE}, the additional cumulative and wave-turbulence interaction terms are computed in the same way.
Assuming that any breaking
wave instantly dissipates all the energy of all waves with frequencies higher
than a factor $r_{\mathrm{cu}}$ or more, the cumulative dissipation rate is
simply given by the rate at which these shorter waves are taken over by larger
breaking waves, times the spectral density, namely
\begin{equation}
\cS_{\mathrm{bk,cu}}(k,\theta) = -C_{\mathrm{cu}}  N \left(k,\theta\right) \int_{f' < r_{\mathrm{cu}} f } \Delta_C \Lambda(\mathbf{k'}) \mathrm{d\mathbf{k'}},
\label{Sds_cu1}
\end{equation}
where $r_{\mathrm{cu}}$ defines the maximum ratio of the frequencies of long
waves that will wipe out short waves.  This gives the source term,
\begin{eqnarray}
\cS_{\mathrm{bk,cu}}(k,\theta) &=&  \frac{-14.2 C_{\mathrm{cu}}}{\pi^2}  N \left(k,\theta\right)
 \nonumber \\
& &\int_0^{ r^2_{\mathrm{cu}} k }\int_0^{2\pi}
\max \left\{\sqrt{B(f',\theta')}-\sqrt{B_r},0\right\}^2
\mathrm{d}\theta' \mathrm{d}k'.
\label{Sds_sat_isotropic}
\end{eqnarray}
We shall take $r_{\mathrm{cu}}=0.5$, and $C_{\mathrm{cu}}$ is a tuning
coefficient expected to be of order 1, which also corrects for errors in the
estimation of $l$.

Finally, the wave-turbulence interaction term of \cite{art:TB02} and \cite{art:AJ06},
is given by

\begin{equation}
\cS_{\mathrm{ds}}^{\mathrm{TURB}}\left(k,\theta\right) = - 2
C_{\mathrm{turb}} \sigma \cos(\theta_u - \theta) k \frac{\rho_a
u_\star^2}{g \rho_w}  N\left(k,\theta\right) .
\end{equation}

\noindent
The coefficient $C_{\mathrm{turb}}$ is of order 1 and can be used to adjust for
ocean stratification and wave groupiness.

All relevant source term parameters can be set via the namelists {\F SIN4} and {\F SDS4}
to yield parameterizations TEST441b, TEST405, both described by
\cite{art:Aea10} or TEST500 described by \cite{art:FA12} (see Tables \ref{tab:ST4_parSIN} and \ref{tab:ST4_parSDS}). Please note that the
DIA constant $C$ has been slightly adjusted in TEST441b, $C=2.5\times
10^7$. TEST441f corresponds to a re-tuned wind input formulation when using
NCEP/NCAR winds.

\begin{landscape}
\begin{table} \begin{center}
%\begin{tabular}{|l|c|c|c|c|c|c|c|c|} \hline \hline
%Par.                               &  WWATCH var.  & namelist  & T471        & T400/$I_{\mathrm{phys}}=1$& T405             & T500         & T601        &  T700      \\
%\hline
% 				    & SDSBCHOICE    & SDS4      &  1          &     1                     &   1              & \textbf{2}   & 1           & \textbf{3} \\
%%  $p$                             &  WNMEANP      & SDS4      & 0.5         & 0.5                       & 0.5              &  0.5    \\
%%  $p_{\mathrm{tail}}$             &  WNMEANPTAIL  & SDS4      & 0.5         & 0.5                   & 0.5 &  0.5 \\
%  $f_{\mathrm{FM}}$                &  FXFM3        & SDS4      & 2.5         & 2.5                       & 2.5              &\textbf{9.9}  & 5           &  \textbf{20} \\
%                                   & SDSC1         & SDS4      & 0           & 0                         & 0                &\textbf{1.0}  & 0           &              \\
%  $C_{\mathrm{ds}}^{\mathrm{sat}}$ & SDSC2         & SDS4      &$-2.2\X^{-5}$&$-2.2\X^{-5}$              &$-2.2\X^{-5}$     &\textbf{0.0}  &$-2.2\X^{-5}$& \textbf{-3.8}   \\
%  $C_{\mathrm{ds}}^{\mathrm{BCK}}$ & SDSBCK        & SDS4      & 0           & 0                         & 0                &\textbf{0.185}& 0           &   \\
%  $C_{\mathrm{ds}}^{\mathrm{HCK}}$ & SDSHCK        & SDS4      & 0           & 0                         & 0                &\textbf{1.5}  & 0           & \\
%  $\Delta_\theta$                  & SDSDTH        & SDS4      & 80          & 80                        & 80               & 80           &  80         & \\
%  $\delta_\theta$                  & SDSSTRAINA    & SDS4      & 0           & 0                         & 0                & 0            & \textbf{15} &    \\
%  $M_\theta$                       & SDSSTRAIN     & SDS4      & 0           & 0                         & 0                & 0            & \textbf{10} &    \\
%  $N_\theta$                       & SDSSTRAIN2    & SDS4      & 0           & 0                         & 0                & 0            & \textbf{20} & \textbf{0}    \\
%  $B_r$                            & SDSBR         & SDS4      & 0.0009      & 0.0009                    &\textbf{0.00085}  & 0.0009       & 0.0009      & \\
%  $C_{\mathrm{cu}}$                & SDSCUM        & SDS4      & -0.40344    & \textbf{0.0}              & \textbf{0.0}     &-0.40344      &-0.40344     & \\
%  ${\mathrm{s_B}}$                 & SDSCOS        &SDS4       & 2.0         &  2.0                      & \textbf{0.0}     & 2.0          & 2.0         & \\
%  $B_0$                           & SDSC4         & SDS4      & 1.0         & 1.0                       & 1.0              & 1.0          & 1.0          & \\
%  $p^{\mathrm{sat}}$               & SDSP          & SDS4      & 2.0         & 2.0                       & 2.0              & 2.0          & 2.0         & \\
%  $C_{\mathrm{turb}}$              & SDSC5         & SDS4      & 0.0         & 0.0                       &  0.0             & 0.0          & \textbf{1.0}&  \\
%  $\delta_d$                       & SDSC6         & SDS4      & 0.3         & 0.3                       &  0.3             & 0.3          &0.3          & \\
%  $C$                              & NLPROP        & SNL1      & $2.5\X^7$   & $\mathbf{2.7\X^7}$        &$\mathbf{2.7\X^7}$& $2.5\X^7$    & $2.5\X^7$   & \\
% \hline \hline
%\end{tabular}
\begin{tabular}{|l|c|c|c|c|c|c|c|} \hline \hline
Par.                               &  WWATCH var.  & namelist  & T471        & T405             & T500         & T601        & T700  \\
\hline
 				   & SDSBCHOICE    & SDS4      &  1          &     1            & \textbf{2}   & 1           & \textbf{3}  \\
  $f_{\mathrm{FM}}$                &  FXFM3        & SDS4      & 2.5         & 2.5              &\textbf{9.9}  & 5           & \textbf{20} \\
%                                   & SDSC1         & SDS4      & 0           & 0                &\textbf{1.0}  & 0           &    \\
  $C_{\mathrm{ds}}^{\mathrm{sat}}$ & SDSC2         & SDS4      &$-2.2\X^{-5}$&$-2.2\X^{-5}$     &\textbf{0.0}  &$-2.2\X^{-5}$&  \textbf{-3.8}  \\
  $C_{\mathrm{ds}}^{\mathrm{BCK}}$ & SDSBCK        & SDS4      &            &                   & 0.185        &             & \\
  $C_{\mathrm{ds}}^{\mathrm{HCK}}$ & SDSHCK        & SDS4      &            &                   &  1.5         &             & \\
  $\Delta_\theta$                  & SDSDTH        & SDS4      & 80          & 80               & 80           &  80         & \\
  $\delta_\theta$                  & SDSSTRAINA    & SDS4      & 0           & 0                & 0            & \textbf{15} &  0  \\
  $M_\theta$                       & SDSSTRAIN     & SDS4      & 0           & 0                & 0            & \textbf{10} &  0  \\
  $N_\theta$                       & SDSSTRAIN2    & SDS4      & 0           & 0                & 0            & \textbf{20} &  \textbf{0}   \\
  $B_r$                            & SDSBR         & SDS4      & 0.0009      &\textbf{0.00085}  & 0.0009       & 0.0009      &  \textbf{0.005}  \\
  $B_r$                            & SDSBT         & SDS4      &             &                  &              &             &    0.0011     \\
  $C_{\mathrm{cu}}$                & SDSCUM        & SDS4      & -0.40344    & \textbf{0.0}     &-0.40344      &-0.40344     & \textbf{0.0} \\
  ${\mathrm{s_B}}$                 & SDSCOS        &SDS4       & 2.0         & \textbf{0.0}     & 2.0          & 2.0         &     \\
  $p^{\mathrm{sat}}$               & SDSP          & SDS4      & 2.0         & 2.0              & 2.0          & 2.0         &     \\
  $C_{\mathrm{turb}}$              & SDSC5         & SDS4      & 0.0         &  0.0             & 0.0          & \textbf{1.0}& 0.0 \\
  $\delta_d$                       & SDSC6         & SDS4      & 0.3         &  0.3             & 0.3          &0.3          & \\
  $ M_W$			   & SDSMWD	   & SDS4      &            &                   &              &             & 0.9 \\
  $ M_\Lambda$			   & SDSFACMTF	   & SDS4      &            &                   &              &             & 400 \\
  $C$                              & NLPROP        & SNL1      & $2.5\X^7$   &$\mathbf{2.7\X^7}$& $2.5\X^7$    & $2.5\X^7$   & $2.5\X^7$ \\
 % $p_{\mathrm{mss}}$              &  SPMSS         & SDS4      &            &                   &             &             &  0.5 \\
 \hline \hline
\end{tabular}
\end{center}

\caption{Same as Table \ref{tab:ST4_parSIN}, for the {\F SDS4} and {\F SNL1}
namelists. Bold values are different from the default values set by
 ww3\_grid. Values are omitted when the SDSBCHOICE makes them not used. Note that \cite{Romero2019} suggests using  $ M_W=2$ when NL2 is used.	 } \label{tab:ST4_parSDS}
%\botline
\end{table}
\end{landscape}


%!TEX program = xelatex
% 完整编译: xelatex(cn) -> bibtex(cn) -> xelatex(cn) -> xelatex(cn) -> xelatex(en)
\documentclass[lang=en,11pt,a4paper,cite=numbers]{elegantpaper}
\usepackage{xfp}
\usepackage{tikz}

\title{Manifold}
\author{Hui Zheng}
% \institute{}

% \version{0.09}
\date{\today}

% 本文档命令
\usepackage{array}
\newcommand{\ccr}[1]{\makecell{{\color{#1}\rule{1cm}{1cm}}}}

\begin{document}

\maketitle

\begin{abstract}
  The definition of Manifold.
\keywords{Manifold}
\end{abstract}

\section{Manifold\cite{manifold}}
  A manifold is a topological space\ref{terms:topological-space} that is locally Euclidean (i.e., around every point, there is a neighborhood that is topologically the same as the open\ref{terms:open-set} unit ball in $\mathbb{R}^{n}$). To illustrate this idea, consider the ancient belief that the Earth was flat as contrasted with the modern evidence that it is round. The discrepancy arises essentially from the fact that on the small scales that we see, the Earth does indeed look flat. In general, any object that is nearly "flat" on small scales is a manifold, and so manifolds constitute a generalization of objects we could live on in which we would encounter the round/flat Earth problem, as first codified by Poincar$\rm{\acute{e}}$.

  More concisely, any object that can be "charted" is a manifold.
\begin{figure}[!htb]
  \centering
  \includegraphics[width=0.4\textwidth]{figs/manifold.png}
  \caption{figs:manifold}
  \label{figs:manifold}
\end{figure}

  One of the goals of topology is to find ways of distinguishing manifolds. For instance, a circle is topologically the same as any closed loop, no matter how different these two manifolds may appear. Similarly, the surface of a coffee mug with a handle is topologically the same as the surface of the donut, and this type of surface is called a (one-handled) torus\ref{terms:torus}.

  As a topological space, a manifold can be compact or noncompact, and connected or disconnected. Commonly, the unqualified term "manifold"is used to mean "manifold with boundary." This is the usage followed in this work. However, an author will sometimes be more precise and use the term open manifold for a noncompact manifold without boundary or closed manifold for a compact manifold with boundary.

  If a manifold contains its own boundary, it is called, not surprisingly, a "manifold with boundary." The closed unit ball in $\mathbb{R}^n$ is a manifold with boundary, and its boundary is the unit sphere. The concept can be generalized to manifolds with corners. By definition, every point on a manifold has a neighborhood together with a homeomorphism of that neighborhood with an open ball in $\mathbb{R}^n$. In addition, a manifold must have a second countable topology. Unless otherwise indicated, a manifold is assumed to have finite dimension $n$, for $n$ a positive integer.

  Smooth manifolds (also called differentiable manifolds) are manifolds for which overlapping charts "relate smoothly" to each other, meaning that the inverse of one followed by the other is an infinitely differentiable map from Euclidean space to itself. Manifolds arise naturally in a variety of mathematical and physical applications as "global objects." For example, in order to precisely describe all the configurations of a robot arm or all the possible positions and momenta of a rocket, an object is needed to store all of these parameters. The objects that crop up are manifolds. From the geometric perspective, manifolds represent the profound idea having to do with global versus local properties.

  The basic example of a manifold is Euclidean space, and many of its properties carry over to manifolds. In addition, any smooth boundary of a subset of Euclidean space, like the circle or the sphere, is a manifold. Manifolds are therefore of interest in the study of geometry, topology, and analysis.

  A submanifold is a subset of a manifold that is itself a manifold, but has smaller dimension. For example, the equator of a sphere is a submanifold. Many common examples of manifolds are submanifolds of Euclidean space. In fact, Whitney showed in the 1930s that any manifold can be embedded in $\mathbb{R}^N$, where $N=2n+1$.

  A manifold may be endowed with more structure than a locally Euclidean topology. For example, it could be smooth, complex, or even algebraic (in order of specificity). A smooth manifold with a metric is called a Riemannian manifold, and one with a symplectic structure is called a symplectic manifold. Finally, a complex manifold with a Kähler structure is called a Kähler manifold.

\section{Topological Space\cite{topological-space}}
\label{terms:topological-space}
  A topological space, also called an abstract topological space, is a set $X$ together with a collection of open subsets $T$ that satisfies the four conditions:
\begin{enumerate}
  \item The empty set $\emptyset$ is in $T$.
  \item $X$ is in $T$.
  \item The intersection of a finite number of sets in $T$ is also in $T$.
  \item The union of an arbitrary number of sets in $T$ is also in $T$.
\end{enumerate}
Alternatively, $T$ may be defined to be the closed sets rather than the open sets, in which case conditions 3 and 4 become:
\newcounter{counter}
\setcounter{counter}{2}
\begin{enumerate}[\thecounter.]
  \stepcounter{counter}
  \item The intersection of an arbitrary number of sets in $T$ is also in $T$.
  \stepcounter{counter}
  \item The union of a finite number of sets in $T$ is also in $T$.
\end{enumerate}
These axioms are designed so that the traditional definitions of open and closed intervals of the real line continue to be true. For example, the restriction in (3) can be seen to be necessary by considering  $\cap_{(n=1)}^{\infty}(-\frac{1}{n},\frac{1}{n})=\{0\}$, where an infinite intersection of open intervals is a closed set.

  In the chapter "Point Sets in General Spaces" Hausdorff (1914) defined his concept of a topological space based on the four Hausdorff axioms (which in modern times are not considered necessary in the definition of a topological space).

\section{Open Set\cite{open-set}}
\label{terms:open-set}
\begin{figure}[!htb]
  \centering
  \includegraphics[width=0.4\textwidth]{figs/open-set.png}
  \caption{figs:open-set}
  \label{figs:open-set}
\end{figure}
  Let $S$ be a subset of a metric space. Then the set $S$ is open if every point in $S$ has a neighborhood lying in the set. An open set of radius $r$ and center $\textbf{x}_{0}$ is the set of all points $\textbf{x}$ such that $\left|\textbf{x}-\textbf{x}_{0}\right|{\le}r$, and is denoted $D_{r}(\textbf{x}_{0})$. In one-space, the open set is an open interval. In two-space, the open set is a disk. In three-space, the open set is a ball.

  More generally, given a topology(consisting of a set $X$ and a collection of subsets $T$), a set is said to open if it is in $T$. Therefore, while it is not possible for a set to be both finite and open in the topology of the real line(a single point is a closed set), it is possible for a more general topological set to be both finite and open.

  The complement of an open set is closed set. It is possible for a set to be neither open nor closed, e.g., the half-closed interval$(0,1]$.

\section{Torus\cite{torus}}
\label{terms:torus}
\begin{figure}[!htb]
  \centering
  \includegraphics[width=0.6\textwidth]{figs/torus.png}
  \caption{figs:torus}
  \label{figs:torus}
\end{figure}
  An (ordinary) torus is a surface having genus\ref{terms:torus-genus} one, and therefore possessing a single "hole" (left figure). The single-holed "ring" torus is known in older literature as an "anchor ring." It can be constructed from a rectangle by gluing both pairs of opposite edges together with no twists (right figure; Gardner 1971, pp. 15-17; Gray 1997, pp. 323-324). The usual torus embedded in three-dimensional space is shaped like a donut, but the concept of the torus is extremely useful in higher dimensional space as well.

  In general, tori can also have multiple holes, with the term n-torus used for a torus with $n$ holes. The special case of a 2-torus is sometimes called the double torus, the 3-torus is called the triple torus, and the usual single-holed torus is then simple called "the" or "a" torus.

  A second definition for $n$-tori relates to dimensionality. In one dimension, a line bends into circle, giving the 1-torus. In two dimensions, a rectangle wraps to a usual torus, also called the 2-torus. In three dimensions, the cube wraps to form a 3-manifold, or 3-torus. In each case, the $n$-torus is an object that exists in dimension $n+1$. One of the more common uses of $n$-dimensional tori is in dynamical systems\ref{terms:torus-dynamical-systems}. A fundamental result states that the phase space trajectories of a Hamiltonian system with $n$ degrees of freedom and possessing $n$ integrals of motion lie on an $n$-dimensional manifold which is topologically equivalent to an $n$-torus (Tabor 1989).

  Torus coloring of an ordinary (one-holed) torus requires 7 colors, consistent with the Heawood conjecture.

  Let the radius from the center of the hole to the center of the torus tube be $c$, and the radius of the tube be $a$. Then the equation in Cartesian coordinates for a torus azimuthally symmetric about the z-axis is
\begin{equation}
   \left(c-\sqrt{(x^{2}+y^{2})}\right)^{2}+z^{2}=a^{2}
\end{equation}
and the parametric equations are
\begin{equation}
  \begin{aligned}
    x&=(c+a\rm{cos}v)\rm{cos}u\\
    y&=(c+a\rm{cos}v)\rm{sin}u\\
    z&=a\rm{sin}v
  \end{aligned}
\end{equation}
for $u,v \in [0,2pi)$. Three types of torus, known as the standard tori, are possible, depending on the relative sizes of $a$ and $c$. $c>a$ corresponds to the ring torus (shown above), $c=a$ corresponds to a horn torus which is tangent to itself at the point (0, 0, 0), and $c<a$ corresponds to a self-intersecting spindle torus (Pinkall 1986).

  If no specification is made, "torus" is taken to mean ring torus. The three standard tori are illustrated below, where the first image shows the full torus, the second a cut-away of the bottom half, and the third a cross section of a plane passing through the z-axis.
\begin{figure}[!htb]
  \centering
  \includegraphics[width=0.6\textwidth]{figs/torus-types.png}
  \caption{figs:torus-types}
  \label{figs:torus-types}
\end{figure}

  The standard tori and their inversions are cyclides. If the coefficient of $\rm{sin}v$ in the formula for $z$ is changed to $b{\neq}a$, an elliptic torus results.
\begin{figure}[!htb]
  \centering
  \includegraphics[width=0.6\textwidth]{figs/elliptic-torus.png}
  \caption{figs:elliptic-torus}
  \label{figs:elliptic-torus}
\end{figure}
To compute the metric properties of the ring torus, define the inner and outer radii by
\begin{equation}
  \begin{aligned}
    r&{\equiv}c-a\\
    R&{\equiv}c+a
  \end{aligned}
\end{equation}
Solving for a and c gives
\begin{equation}
  \begin{aligned}
    a&=\frac{1}{2}(R-r)\\
    c&=\frac{1}{2}(R+r)
  \end{aligned}
\end{equation}
Then the surface area of this torus is
\begin{equation}
  \begin{aligned}
    S&=(2{\pi}a)(2{\pi}c)\\
     &=4{\pi}^{2}ac\\
     &={\pi}^{2}(R+r)(R-r)^{2}
  \end{aligned}
\end{equation}
The volume can also be found by integrating the Jacobian computed from the parametric equations of the solid,
\begin{equation}
  \begin{aligned}
    x&=(c+r'\rm{cos}v)\rm{cos}u\\
    y&=(c+r'\rm{cos}v)\rm{sin}u\\
    z&=r'\rm{sin}v
  \end{aligned}
\end{equation}
which simplifies to
\begin{equation}
  \begin{aligned}
    J&=\left|\frac{{\partial}(x,y,z)}{{\partial}(u,v,r')}\right|=r'(c+r'\rm{cos}v)
  \end{aligned}
\end{equation}
giving
\begin{equation}
  \begin{aligned}
    V&=\int^{2\pi}_{0}\int^{2\pi}_{0}\int^{a}_{0}r'(c+r'\rm{cos}v)dr'dudv\\
     &=2{\pi}^{2}a^{2}c
  \end{aligned}
\end{equation}
as before.

  The moment of inertia tensor of a solid torus with mass $M$ is given by
\begin{equation}
  \begin{aligned}
    V&=\begin{bmatrix}
      (\frac{5}{8}a^{2}+\frac{1}{2}c^{2})M & 0 & 0 \\
      0 & (\frac{5}{8}a^{2}+\frac{1}{2}c^{2})M & 0 \\
      0 & 0 & (\frac{3}{4}a^{2}+c^{2})M
    \end{bmatrix}
  \end{aligned}
\end{equation}
The coefficients of the first fundamental form are
\begin{equation}
  \begin{aligned}
    E&=(c+a\rm{cos}v)^{2}\\
    F&=0\\
    G&=a^{2}
  \end{aligned}
\end{equation}
and the coefficients of the second fundamental form are
\begin{equation}
  \begin{aligned}
    e&=-(c+a\rm{cos}v)\rm{cos}v\\
    f&=0\\
    G&=-a
  \end{aligned}
\end{equation}
giving Riemannian metric
\begin{equation}
  \begin{aligned}
    ds^{2}&=(c+a\rm{cos}v)^{2}du^{2}+a^{2}dv^{2}
  \end{aligned}
\end{equation}
area element
\begin{equation}
  \begin{aligned}
    dA&=a(c+a\rm{cos}v)du{\land}dv
  \end{aligned}
\end{equation}
(where $du{\land}dv$ is a wedge product), and Gaussian and mean curvatures as
\begin{equation}
  \begin{aligned}
    K&=\frac{\rm{cos}v}{a(c+a\rm{cos}v)}\\
    H&=-\frac{c+2a\rm{cos}v}{2a(c+a\rm{cos}v)}
  \end{aligned}
\end{equation}
(Gray 1997, pp. 384-386).

  A torus with a hole in its surface can be turned inside out to yield an identical torus. A torus can be knotted externally or internally, but not both. These two cases are ambient isotopies, but not regular isotopies. There are therefore three possible ways of embedding a torus with zero or one knot.
\begin{figure}[!htb]
  \centering
  \includegraphics[width=0.6\textwidth]{figs/ambient-isotopies.png}
  \caption{figs:ambient-isotopies}
  \label{figs:ambient-isotopies}
\end{figure}

  An arbitrary point P on a torus (not lying in the xy-plane) can have four circles drawn through it. The first circle is in the plane of the torus and the second is perpendicular to it. The third and fourth circles are called Villarceau circles (Villarceau 1848, Schmidt 1950, Coxeter 1969, Melnick 1983).

\subsection{Genus\cite{genus}}
\label{terms:torus-genus}
  A topologically invariant property of a surface defined as the largest number of nonintersecting simple closed curves that can be drawn on the surface without separating it. Roughly speaking, it is the number of holes in a surface.

  The genus of a surface, also called the geometric genus, is related to the Euler characteristic\ref{terms:torus-euler-characteristic} $\chi$. For a orientable surface such as a sphere (genus 0) or torus (genus 1), the relationship is
\begin{equation}
  {\chi}=2-2g
\end{equation}

  For a nonorientable surface such as a real projective plane (genus 1) or Klein bottle (genus 2), the relationship is
\begin{equation}
  {\chi}=2-g
\end{equation}
(Massey 2003).

\subsection{Euler Characteristic\cite{euler-characteristic}}
\label{terms:torus-euler-characteristic}
  Let a closed surface have genus g. Then the polyhedral formula generalizes to the Poincar$\rm{\acute{e}}$ formula
\begin{equation}
  {\chi}(g){\equiv}V-E+F,
\end{equation}
where
\begin{equation}
  {\chi}(g)=2-2g
\end{equation}
is the Euler characteristic, sometimes also known as the Euler-Poincar$\rm{\acute{e}}$ characteristic. The polyhedral formula corresponds to the special case $g=0$.

  The only compact closed surfaces with Euler characteristic 0 are the Klein bottle and torus (Dodson and Parker 1997, p. 125). The following table gives the Euler characteristics for some common surfaces (Henle 1994, pp. 167 and 295; Alexandroff 1998, p. 99).
\begin{table}[htbp]
  \centering
  \begin{tabular}{c|c}
    \hline
    surface & $\chi$ \\
    \hline
    cylinder & 0 \\
    double torus & -2 \\
    Klein bottle & 0 \\
    M$\rm{\ddot{o}}$bius strip & 0 \\
    projective plane & 1 \\
    sphere & 2 \\
    torus & 0 \\
    \hline
  \end{tabular}
\end{table}

  In terms of the integral curvature of the surface $K$,
\begin{equation}
  {\iint}Kda=2{\pi}{\chi}
\end{equation}
The Euler characteristic is sometimes also called the Euler number. It can also be expressed as
\begin{equation}
  {\chi}=p_{0}-p_{1}+p_{2}
\end{equation}
where $p_i$ is the ith Betti number of the space.

\subsection{Dynamical Systems\cite{dynamical-systems}}
\label{terms:torus-dynamical-systems}
  A means of describing how one state develops into another state over the course of time. Technically, a dynamical system is a smooth action of the reals or the integers on another object (usually a manifold). When the reals are acting, the system is called a continuous dynamical system, and when the integers are acting, the system is called a discrete dynamical system. If $f$ is any continuous function, then the evolution of a variable $x$ can be given by the formula
\begin{equation}
  x_{n+1}=f(x_{n})
\end{equation}
This equation can also be viewed as a difference equation
\begin{equation}
  x_{n+1}-x_{n}=f(x_{n})-x_{n}
\end{equation}
so defining
\begin{equation}
  g(x){\equiv}f(x)-x
\end{equation}
gives
\begin{equation}
  x_{n+1}-x_{n}=g(x_{n})*1
\end{equation}
which can be read "as $n$ changes by 1 unit, $x$ changes by $g(x)$." This is the discrete analog of the differential equation
\begin{equation}
  x'(n)=g(x(n))
\end{equation}

%\nocite{*}
\bibliography{ref/refs}

\end{document}


% !TeX root = ../main.tex
\section{Basic Narrowing}
We now study a restricted form or narrowing, called basic narrowing. It was introduced by Hullot on his famous paper \textit{Canonical Forms and Unification} (\cite{hullot:cfunif}). Intuitively, basic narrowing makes a restriction on the possible positions a redex can be contracted. The idea is that one can not narrow positions that were introduced by some other narrowing substitution. Hullot shows in \cite{hullot:cfunif} that basic narrowing is still complete for $E$-unification problems such that $E$ can be represented by a convergent term rewrite system $\trs$.

This restriction was motivated by the very large search space of standard narrowing. The search space for narrowing is quite large in applications and this is a step back when solving equations on \textit{resolutions steps}\footnote{We study some applications of narrowing in solving SLD-resolution later in the report.} (based on narrowing) and automated reasoning. For example, in Example \ref{example:app-concat-standard-narrowing} the search space is a infinite set.

To ease the exposition and focusing the attention only on solving equations making clear the role of TRS in reductions, we temporally abandon the transformation rules approach. We return to this approach later when considering improvements of basic narrowing.

We do this by assuming that $\trs$ contain the additional rewrite rule $eq(x,x) \contr true$ and consider terms of the following form:
\begin{itemize}
	\item terms that do not contain any occurrences of $eq$ and $true$
	\item terms $eq(s,t)$ with $s,t$ satisfying the previous condition
	\item the constant $true$
\end{itemize}
Terms of the second form are called goals. It should be noted that confluence, completeness and semi-completeness are retained under the addition of the rule $eq(x,x) \contr true$.

\begin{definition}
	\begin{enumerate}
		\item Let $t_1 \narrow_{[p_1, l_1 \contr r_1, \sigma_1]} t_2 \narrow_{[p_2, l_2 \contr r_2, \sigma_2]} \cdots \narrow_{[p_{n-1}, l_{n-1} \contr r_{n-1}, \sigma_{n-1}]} t_n$ be a narrowing derivation. Define sets of positions $B_1, \cdots, B_n$ inductively as follows:
		      \begin{align*}
			      B_1     & = \basicPos{t_1}                                            \\
			      B_{i+1} & = \mathbb{B}(B_i, p_i, r_i) \qquad \text{for } 1 \leq i < n
		      \end{align*}
		      Where $\mathbb{B}(B_i, p_i, r_i) := (B_i \setminus \{ q \in B_i \mid p_i \leq q \}) \cup \{ p_iq \mid q \in \basicPos{r_i} \}$. Positions in $B_i$ are referred to as basic positions and positions in $\basicPos{t_i} \setminus B_i$ are called non-basic positions. Call the above narrowing derivation basic if $p_i \in B_i$ for $1 \leq i < n$.
		\item A rewrite sequence
		      $$t_1 \contr_{[p_1, l_1 \contr r_1, \sigma_1]} t_2 \contr_{[p_2, l_2 \contr r_2, \sigma_2]} \cdots \contr_{[p_{n-1}, l_{n-1} \contr r_{n-1}, \sigma_{n-1}]} t_n$$
		      is based on a set of positions $B_1 \subseteq \basicPos{t_1}$ if $p_i \in B_i$ for $1 \leq i < n$ with $B_2, \dots, B_n$ defined as above.
	\end{enumerate}
\end{definition}

Now the problem is to prove the completeness of $E$-unification based on basic narrowing. The strategy is still the same: lift basic $\contr$-derivations to basic $narrow$-derivations by using the lifting lemma. To complete this task one needs to prove $\contr$-derivations are basic before they are lifted by lifting lemma. To complete this task, Hullot asserts in \cite{hullot:cfunif} the following Lemma, (Lemma 3 in his paper).

\begin{lemma}[Hullot, Lemma 3]
	Let $t = s\sigma$ with some normalised substitution $\sigma$. Every $\contr$-reduction from $t$ is based on $\basicPos{s}$.
\end{lemma}

\begin{example}[\cite{10.1007/3-540-51564-X_51} Example 3]\label{example:hullot-counter-ex}
	Let $\trs = \{ f(x,b) \contr g(x), a \contr b \}$. We can see that a reduction sequence
	$$f(a,b) \contr f(b,b) \contr g(b)$$
	is based on $\basicPos{t}$, but
	$$f(a,b) \contr g(a) \contr g(b)$$
	is not.
\end{example}

However, the second sequence in Example \ref{example:hullot-counter-ex} does not satisfy the Hullot assertion. Therefore, his proof for completeness of basic narrowing does not work.

In the first sequence of Example \ref{example:hullot-counter-ex}, only innermost redexes are contracted. On the other hand, in the second one $f(a,b)$ is selected and it is not an innermost redex since it contains the redex $a$ as subterm. This selection makes a counterexample for Lemma 3 in Hullot paper.

In general, when ones construct a basic reduction sequence from a term $t$ to $\trsNF{t}$, the terms introduced by the substitution at each reduction need to be in normal form because they may not be selected as redexes. From these considerations, Yamamoto (\cite{10.1007/3-540-51564-X_51}) made the suggestion that the innermost occurrence should essentially owe to the completeness of basic narrowing.

\begin{definition}
	An innermost redex does not contain (as a subterm) any other redexes. In an innermost reduction sequence, only innermost redexes are contracted.
\end{definition}

Now, with the innermost selection of redexes we can guarantee that reductions sequence is basic.

\begin{proposition}\label{proposition:innermost-based-on-t}
	Let $\trs$ be a TRS and $\sigma$ a normalised substitution. Every innermost reduction sequence starting from $t\sigma$ is based on $\basicPos{t}$.
	\begin{proof}
		The proof is by induction on the length of the reduction. For the base case suppose we have a sequence
		$$ t\sigma = t_1 \contr_{[p_1, l_1 \contr r_1, \sigma_1]} t_2 $$
		We need to show that $p_1 \in B_1 = \basicPos{t_1}$. It follows that any redex of $t_1$ must be in $\basicPos{t_1}$ since $\sigma$ is a normalised substitution.
		Now consider the reduction of length $n$ starting from $t_1$, that is,
		$$t \sigma = t_1 \contr_{[p_1, l_1 \contr r_1, \sigma_1]} t_2 \contr_{[p_2, l_2 \contr r_2, \sigma_2]} \cdots \contr_{[p_{n-1}, l_{n-1} \contr r_{n-1}, \sigma_{n-1}]} t_n$$
		By induction on $i$ we must show that $\restr{p_i}{p}$ is a normal form for all $p$ in $\pos{t_i}\setminus B_i$ for $1 \leq i \leq n$. Suppose the statement holds for $i = 1, \dots, m$ and let $p \in \pos{t_{m+1}} \setminus B_{m+1}$. There are two possible cases: $\parPos{p}{p_m}$ or $p_m \leq p$. Note that the case $p < p_m$ is impossible since this would imply $p \in B_{m+1}$, because $B_m$ is closed under prefix and $p_m \in B_m$.
		\begin{enumerate}
			\item If $\parPos{p}{p_m}$ then $p \notin B_m$ by construction. So $p \in \pos{t_m} \setminus B_m$ and $\restr{t_{m+1}}{p} = \restr{t_m}{p}$ and the induction hypothesis give us the result.
			\item Suppose $p_m \leq p$, then there exists positions $q \in \varPos{r_m}$ and $q'$ such that $p = p_m q q'$ (otherwise, $p \in B_{m+1})$. Hence
			      $$\restr{t_{m+1}}{p} = \restr{r_m\sigma_m}{qq'} = \restr{x\sigma_m}{q'}$$
			      where $x$ is a variable in $r_m$ at position $q$. So $\restr{t_{m+1}}{p}$ is a proper subterm of $l_m\sigma_m$ and since $t_m \contr_{[p_m, l_m \contr r_m, \sigma_m]}t_{m+1}$ is a innermost reduction step $\restr{t_{m+1}}{p}$ is a normal form.
		\end{enumerate}
	\end{proof}
\end{proposition}

If $\trs$ is convergent, then $\trs$ has the property that there exists an innermost reduction sequence from every term $t$ to its normal form $\trsNF{t}$. However, this is not true in general. In what follows we work under the hypothesis that $\trs$ satisfy this property.

\begin{definition}
	A TRS $\trs$ is \textit{normalising with innermost reductions} if for every term there exists an innermost reduction sequence to its normal form.
\end{definition}

\begin{theorem}
	If $\trs$ is confluent and \textit{normalising with innermost reductions} then basic narrowing is complete for $\trs$-unification problems.
	\begin{proof}
		Suppose that $s\sigma \eqUnif{\trs} t\sigma$. Let $\trsNF{\sigma}$ be the normal form of $\sigma$. Notice that $\sigma \eqUnif{\trs} \trsNF{\sigma}$ and $\trsNF{\sigma} \eqUnif{\trs} t\trsNF{\sigma}$. Confluence of $\trs$ yields the joinability of $s\trsNF{\sigma}$ and $t \trsNF{\sigma}$. Hence there exists a rewrite sequence $eq(s,t)\trsNF{\sigma} \stc true$. We may assume that this reduction is innermost, since $\trs$ is normalising with innermost reduction.

		By the above proposition, this reduction is based on $\basicPos{eq(s,t)}$. Now by the lifting lemma we can lift this $\contr$-derivation to a narrowing derivation $eq(s,t) \narrow_{\gamma}^{*} true$ (considering $V = \vars{s,t}$) such that in each step we use the same rewrite rules at the same positions. It follows that the narrowing derivation $eq(s,t) \narrow_\gamma^* true$ is basic and based on $B_1 = \basicPos{eq(s,t)}$.

		It remains to show that $\gamma \leq^V \trsNF{\sigma}$. In fact, the lifting lemma give us a substitution $\eta$ such that $\gamma \eta \eqUnif{E}^V \trsNF{\sigma}$. So, the result follows.
	\end{proof}
\end{theorem}

\begin{remark}
	It is still possible to extend the left (right) narrowing rules from tables \ref{table:unify_inf_rules} and \ref{table:narrowing_inf_rules} by making only basic narrowing steps. The completeness proof for this extension is exactly as in Theorem \ref{theorem:narrowing-completeness} with minor changes about innermost reductions.
\end{remark}

We can run some tests to see how basic narrowing cut-down the search space of solving equations modulo an equational theory $E$. In fact, remember from Example \ref{example:app-concat-standard-narrowing} that the equation $eq(\appFunc{\appFunc{x}{y}}{z}, \nilList)$ have an infinite search space with standard narrowing. Compare this with the figure below.

\begin{landscape}
	\thispagestyle{empty}
	\hrule
	\begin{figure}[!ht]
		\begin{displaymath}
			\xymatrix{
				& eq(\appFunc{\appFunc{x}{y}}{z}, \nilList) \ar@{~>}[dr] \ar@{~>}[dl] \\
				eq(\appFunc{x_1}{z},\nilList) \ar@{~>}[d] & & eq(\appFunc{w_1 \cdot \appFunc{y_1}{u_1}}{z}, \nilList) \ar@{~>}[d]\\
				eq(x_2,\nilList) \ar@{~>}[d] & & eq(\appFunc{w_1 \cdot x_5}{z}, \nilList) \ar@{~>}[d]\\
				eq(\nilList, \nilList) \ar@{~>}[d]& & eq(w_1 \cdot \appFunc{x_1}{z}, \nilList) \ar@{~>}[d]\\
				true & & eq(x_6, \nilList) \ar@{~>}[d]\\
				& & eq(\nilList, \nilList) \ar@{~>}[d]\\
				& & true
			}
		\end{displaymath}
		\caption{Derivation tree for the objective $eq(\appFunc{\appFunc{x}{y}}{z}, \nilList)$}
		\label{figure:example:app:derivation-tree-basic-narrowing}
	\end{figure}
	\hrule
	\vspace{1cm}
	Note that now the derivation tree is even finite.
\end{landscape}

The reader may ask himself when such problems have finite search spaces. Hullot, \cite{hullot:cfunif} gives a beautiful result in this matter.

\begin{proposition}[Hullot, \cite{hullot:cfunif} Proposition 1]\label{proposition:narrowing-as-E-unification}
	Let $\trs = \{ l_1 \contr r_i \}$, $1 \leq i \leq n$ be a convergent term rewrite system such that any $\narrow$-derivation issue from any of the $r_i$'s terminates. Then any $\narrow$-derivation issue from any term terminates.
\end{proposition}

If the proposition above holds for $\trs$ then the rules (1)-(8) from tables \ref{table:unify_inf_rules} and \ref{table:narrowing_inf_rules} give a complete finite $\trs$-unification algorithm.

In the next section, we give a better formulation of basic narrowing by means of transformation rules on sets of equations. We also study some efficiency rules for the performance of basic narrowing. For now, let us focus on completeness results.

In \cite{10.1007/3-540-51564-X_51} Yamamoto made the following conjecture:
\begin{center}
    \textit{Basic narrowing is complete for semi-convergent TRSs}.
\end{center}
This was conjectured to be true by many other authors. However, in 1994 Middeldorp and Hamoen in \cite{Middeldorp1994} gave a counterexample for this conjecture.

Consider the TRS
\begin{displaymath}
    \trs =
	\begin{cases}
		f(x) & \contr g(x,x)                               \\
        a & \contr b \\
        g(a,b) & \contr c \\
        g(b,b) & \contr f(a)
	\end{cases}
\end{displaymath}

It follows that $\trs$ is confluent and weakly normalising, hence semi-convergent. However, the goal $eq(f(a),c)$ cannot be solved by basic narrowing. The figure below shows all narrowing derivations starting from this goal. Recall that non-basic positions are marked by underline. Since the goal $eq(f(a),c)$ is variable-free, all narrowing steps are also rewrite steps. The steps marked by a star are non-basic because each of them narrows an occurrence of the term $a$ introduced by the narrowing substitution $[x / a]$.
\begin{figure}[!ht]
    \begin{displaymath}
        \xymatrix{
            & eq(f(a),c)\ar@{~>}[dr] \ar@{~>}[dl] &  &  &  \\
            eq(f(b),c) &  & eq(g(\underline{a},\underline{a}), c) \ar@{~>}[dl]^{\star} \ar@{~>}[dr]_{\star} &  & \\
            & eq(g(b,\underline{a}),c) \ar@{~>}[dr]^{\star} & & eq(g(\underline{a},b),c) \ar@{~>}[dl]_{\star} \ar@{~>}[dr] &\\
            & & eq(g(b,b),c) \ar@{~>}@/^10pc/[lluuur] & & eq(c,c) \ar@{~>}[d]\\
            & &  & & true
        }
    \end{displaymath}
    \caption{Derivation tree for the objective $eq(f(a),c)$}
    \label{figure:counterexample}
\end{figure}

Note that (from figure above) all successful derivation step passes through a marked derivation step, basic narrowing is unable to solve the normalised goal $eq(g(x,x),c)$ since the only basic narrowing step starting from $eq(g(x,x),c)$ produces the goal $eq(f(a),c)$, this follows from  $eq(g(x,x),c) \narrow_{[x/a]} eq(f(a),c)$. In particular, basic narrowing is not complete for confluent TRS with respect to normalise substitutions, contrary to what was generally believed.


\chapter{Feasibility study using Model Observer}
\label{chap:model_observer}

human and model observer performance ~\cite{Abbey2001}
When evaluating an imaging system, it is often useful to first use a model observer to compute the performance of the system.  One can optimize the imaging system by calculating its performance using the model observer for a particular task with multiple input parameters.  The best observer that can be used is the ideal observer or Bayesian observer, and its defined as the observer that utilizes all statistical information available regarding the task to maximize task performance as measured by Bayes risk or some other related measure of performance \citep{Barrett2004}.  However this method requires us to know the exact statistical properties about our imaging system, which is next to impossible.  A much simpler observer is the Hotelling observer that only requires us to know the mean and variance of our images.  Although this sounds simple, even the Hotelling observer is extremely computationally intensive and very impractical.  So we opted to use the next best thing, the channelized Hotellinng observer,  to measure the system performance.
The channels essentially approximate the Hotelling observer by a number of channels, or mathematical functions.  Different channels can be selected depending on the tasks at hand.  An advantage to use the channelized Hotelling observer is that they require less computation to calculate the covariance matrix of the observer.

\comment{
What is model observers?\\
what is it used for?\\
what makes them special?\\
what is an ideal observer?\\
mathematical format and significance \\
what's hotelling observer\\
what's channelized hotelling observer\\
types of channels\\
what makes them special\\
}
~\cite{Fan2010}
\citep{Barrett2004}

\section{Background}

provide equation of Hotelling observer, channelized hotelling observer, channels\\
why do I use this type of channels\\
object model\\
detector model\\

In x-ray imaging, the x-ray photons are exponentially attenuated when they pass through a material.  For a monochromatic incident x-ray beam, the attenuation of the x-ray depends on the attenuation coefficient of the material.  This can be expressed by \citep{Barrett2004}

\begin{equation}\label{eq:xrayattenutation}
\bar{N}_{m} = \bar{N}_{0} \; \mathrm{exp} \left[ -\int_{0}^{\infty} dl \; \mu( \mathbf{r_{m}} - \mathbf{ \hat{s}_{m}} \; l) \right],
\end{equation}
where $\bar{N}_{0}$ is the mean number of x-ray photons that would strike the detector element m with no object present, $\bf{r}_{m}$ is the 3D vector specifying the location of the detector element m, $\bf{\hat{s}_{m}}$ is a unit vector from the source to detector element m, and $\mu(\bf{r})$ is the attenuation function of the object.  This assumes all rays from the x-ray point source to the detector subtends small angles ($cos(\theta) \approx  1$), so $\bar{N_{0}}$ is the same for all m.  The attenuation function of the object used for the simulation is:

\begin{equation}\label{eq:xraymu}
\mu(\mathbf{r}) = \mu_{H_{2}O} \; sph(\mathbf{r} / D) + \Delta \mu(\mathbf{r})
\end{equation}
where $\mu_{H_{2}O}$ is the attenuation coefficient of water, $\mathbf{r}$ is a 3D vector in Cartesian coordinate, $sph(\mathbf{r}/D)$ is a spherical function of diameter D, where $sph(\mathbf{r}/D) = 1$ for $| \mathbf{r} | < D/2$, and 0 otherwise.  $\Delta \mu(\mathbf{r})$ is the lumpy background model used by Rolland \citep{Rolland1992}.  The lumpy background model is essentially sum of randomly distributed yet equally sized Gaussian blobs and is given by :
\todo[inline]{include special properties of lumpy background?}

\begin{equation}\label{eq:lumpybg}
\Delta \mu(r) = \sum_{j = 1}^{K} \Delta\mu_0 \;
				\mathrm{exp}( - \frac{|\mathbf{r} - \mathbf{r_j}|^2}{2r_b^2})
\end{equation}
where $\mathbf{r_j}$ is a random vector confined to a spherical diameter $d$, $K$ is the number of Gaussian lumps in the background, $\Delta \mu_0$ is the amplitude of the lump, and $r_b$ is the rms radius of the Gaussian lumps.  Note that $K$ is taken from a Poisson distrubtion with mean $\bar{K}$ and $\mathbf{r_j}$ is taken from a uniform distribution.
\todo[inline]{Should I explain why, look it up, I have no idea right now?}
The values $\bar{K}$ and $\Delta \mu_{0}$ are chosen so the mean of the lumpy background is equal to the attenuation of water ($\mathrm{0.02 \; cm^{-1}}$).  Using \eqref{eq:xrayattenutation} the mean number of x-ray photons incident on the detector when $\Delta \mu(r) \ll d$ is

\begin{equation}\label{eq:xrayatten-approx}
\bar{N}_{m} \approx \bar{N}_{0m} \{ 1 - \int_{0}^{\infty} dl \;
\Delta \mu (\mathbf{r_m} - \hat{\mathbf{s}}_m l)\} \equiv
\bar{N}_{0m} [ 1 - \Delta p_m  ],
\end{equation}
where
$\bar{N}_{0m} \equiv \bar{N}_0 \mathrm{exp} \{ -\mu_{H_20} \int_{0}^{\infty} dl \;
\mathrm{sph} [(\mathbf{r}_m - \mathbf{s}_m)/D] \}$ and
$\Delta p_m \equiv \int_{0}^{\infty} dl \; \Delta \mu(\mathbf{r}_m - \mathbf{\hat{s}}_m l )$. Because the read noise has zero mean, we can write the projected value of the object on the detector element m in electron units as

\begin{equation}\label{eq:g_ElectronUnit}
\bar{g}_{m0} = \eta \bar{k}\bar{N}_{0m}[1 - \Delta p_m].
\end{equation}
This is the conditional mean for a single realization of the lumpy background, with the data averaged over the Poisson fluctuation of the number of x-ray photons, over the photoelectron generation process, and over read noise.
\section{Simulation Model}

How does the math works for x-ray\\
the channels used, include pictures\\
why were these channels used\\
show geometry\\
provide the actual numbers that went into the models\\

\section{Results}

pictures of contrast v detail curve\\
what do they mean?\\
what are not accounted for in the simulation?\\
probably certain types of noise, x-ray scatter, etc\\