% -*- mode: noweb; noweb-default-code-mode: R-mode; -*-
\documentclass[article]{tragula}
\usepackage{dsfont}
\usepackage{bbm}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{wasysym}
\usepackage{amssymb}
\usepackage{yfonts}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% declarations for tragula.cls %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%% just as usual
\author{Robin K. S. Hankin\orcid{https://orcid.org/0000-0001-5982-0415}}
\title{Crinkled arcs in Hilbert space}

%% for pretty printing and a nice hypersummary also set:
\Plainauthor{Robin K. S. Hankin}
\Plaintitle{Crinkled arcs in Hilbert space}
\Shorttitle{Crinkled arcs in Hilbert space}

%% an abstract and keywords

\Abstract{
  The concept of crinkled arc illustrates some non-intuitive
  properties of infinite dimensional Hilbert space.  In this short
  document I use the \proglang{R} programming language to numerically
  illustrate properties of a crinkled arc.
}

\Keywords{Crinkled arc, Hilbert space}
\Plainkeywords{Crinkled arc, Hilbert space}
  
%% publication information
%% NOTE: This needs to filled out ONLY IF THE PAPER WAS ACCEPTED.
%% If it was not (yet) accepted, leave them commented.
\Volume{0}
\Issue{0}
%% \Month{September}
\Year{0000}
\Submitdate{0000-00-00}
\Acceptdate{0000-00-00}
\Repository{https://github.com/RobinHankin/crinkled_arc} %% this line for Tragula

%% The address of (at least) one author should be given
%% in the following format:
\Address{
  Robin K. S. Hankin\\
  University of Stirling\\
  Scotland\\
  email: \email{hankin.robin@gmail.com}
}
%% It is also possible to add a telephone and fax number
%% before the e-mail in the following format:
%% Telephone: +43/1/31336-5053
%% Fax: +43/1/31336-734

%% for those who use Sweave please include the following line (with % symbols):
%% need no \usepackage{Sweave.sty}

%% end of declarations %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\SweaveOpts{}

\newcommand{\bx}{\mathbf x}

\begin{document}

\textbf{This document has not been peer-reviewed and is not an
  accepted \textsf{Tragula} publication.  It is intended as an example
  of the style and substance appropriate for submission to
  \textsf{Tragula}.}

A crinkled arc is a continuous curve in Hilbert
space~\citep{halmos1982}.  Consider $f\colon
\left[0,1\right]\longrightarrow X$, where $X$ is a Hilbert space with
inner product $\langle\cdot,\cdot\rangle$.  Assuming~$f$ to be
injective, its image is a {\em crinkled arc} if it is continuous and
possesses the crinkly property: if $0\leqslant a<b\leqslant c<d\leqslant
1$, then $\langle f(b)-f(a),f(d)-f(c)\rangle=0$; that is, the chord
joining $f(b)$ to $f(a)$, and the chord joining $f(d)$ to $f(c)$, are
orthogonal when intervals $\left[a,b\right]$ and $\left[c,d\right]$
are non-overlapping (some authors refer to $f$ itself as the crinkled
arc).  \cite{halmos1982} interprets such a curve as making a sudden
right angle turn at each point, justifying his statements that
(infinite-dimensional) Hilbert space is ``even roomier than it
looks''.  He then observes that every attempt to construct a crinkled
arc results in essentially

\begin{equation}\label{deff}
f(t) = \sum_{n=1}^\infty\bx_n
\frac{
\sin\left(n-1/2\right)\pi t
}{
\left(n-1/2\right)\pi
},\qquad 0\leqslant t\leqslant 1
\end{equation}

where $\bx_i$ are an orthonormal set, $\langle\bx_i,\bx_j\rangle=0$
for $i\neq j$ (\citeauthor{halmos1982} includes a factor of
$\sqrt{2}$).  \cite{vitale1975} proves the uniqueness of
equation~\ref{deff}, up to reparametrization, translations and
scaling, and inclusion.  Establishing that equation~\ref{deff} does
indeed satisfy the crinkly property using symbolic algebra is not
straightforward (see Appendix).  However, numerical verification is
possible and I present below numerical evidence that the Halmos arc
does in fact possess the crinkly property, using \proglang{R}.  Given
the function defined in equation~\ref{deff}, we have

\begin{equation}\label{fbadc}
\begin{split}
\left\langle f(b)-f(a),f(d)-f(c)\right\rangle &=
\left\langle
\sum_{n=1}^\infty\bx_n \frac{\sin\left(n-1/2\right)\pi a}{\left(n-1/2\right)\pi}-
\sum_{n=1}^\infty\bx_n \frac{\sin\left(n-1/2\right)\pi b}{\left(n-1/2\right)\pi},\right.\\
&{}\qquad\qquad\left.
\sum_{n=1}^\infty\bx_n \frac{\sin\left(n-1/2\right)\pi c}{\left(n-1/2\right)\pi}-
\sum_{n=1}^\infty\bx_n \frac{\sin\left(n-1/2\right)\pi d}{\left(n-1/2\right)\pi}
\right\rangle\\
&=
\left\langle
\sum_{n=1}^\infty\bx_n \frac{\sin (ma)}{m}-
\sum_{n=1}^\infty\bx_n \frac{\sin (mb)}{m},
\sum_{n=1}^\infty\bx_n \frac{\sin(mc)}{m}-
\sum_{n=1}^\infty\bx_n \frac{\sin(md)}{m}
\right\rangle\\
 & = \sum_{n=1}^\infty\left(
\frac{\sin (ma)}{m}-
\frac{\sin (mb)}{m}\right)\cdot\left(
\frac{\sin (mc)}{m}-
\frac{\sin (md)}{m}
\right)
\langle\bx_n,\bx_n\rangle
\\
 & = \sum_{n=1}^\infty\frac{
(\sin (ma)-\sin (mb))\cdot
(\sin (mc)-\sin (md))
 }{
m^2
},
\end{split}
\end{equation}

where $m=m(n)=(n-1/2)\pi$: we would like to show that the right hand
side approaches zero as $n\longrightarrow\infty$.
Equation~\ref{fbadc} is easily approximated numerically; below,
function \verb+f()+ calculates the partial sums of the right hand
side:

<<definefunctionf>>=
f <- function(n,a,b,c,d){
  jj <- (n-1/2)*pi
  (sin(jj*b)-sin(jj*a))*(sin(jj*d)-sin(jj*c))/jj^2
}
@

Figure~\ref{plot3} shows a numerical evaluation of the first 100
partial sums of equation~\ref{fbadc} for differing values of
$a,b,c,d$.  Figure~\ref{plot3b} shows a log-log plot of a range of
intervals.

\begin{figure}[h]
  \begin{center}
<<plot3,echo=FALSE, fig=TRUE>>=
plot(NA,xlim=c(0,100),ylim=c(-0.01,0.03),ylab="cumulative sum")
abline(h=0,col='gray')
points(cumsum(f(1:100,a=0.1,b=0.2,c=0.3,d=0.4 )),type="l",col="black")
points(cumsum(f(1:100,a=0.1,b=0.3,c=0.27,d=0.4)),type="l",col="blue")
points(cumsum(f(1:100,a=0.1,b=0.4,c=0.4,d=0.5 )),type="l",col="red")
legend("topright",
       lty=1,pch=NA,
       col=c("black","blue","red"),
       legend=c("a=0.1, b=0.2, c=0.3, d=0.4","a=0.1, b=0.4, c=0.3, d=0.5","a=0.1, b=0.4, c=0.4, d=0.5"))
@
\caption{First 100 \label{plot3} partial sums for $\left\langle
  f(b)-f(a),f(d)-f(c)\right\rangle$ with $a=0.1,b=0.2,c=0.3,d=0.4$
  (nonoverlapping; black), $a=0.1,b=0.4,c=0.3,d=0.5$ (overlapping;
  blue) and $a=0.1,b=0.4,c=0.4,d=0.5$ (abutting; red).  See how the
  nonoverlapping intervals approach zero, the overlapping intervals
  approach a nonzero value, and the abutting intervals approach zero
  but more slowly than the nonoverlapping intervals}
  \end{center}
\end{figure}

\begin{figure}[h]
  \begin{center}
<<plot3b,echo=FALSE, fig=TRUE>>=
f <- function(n,a,b,c,d){
  jj <- (n-1/2)*pi
  (sin(jj*b)-sin(jj*a))*(sin(jj*d)-sin(jj*c))/jj^2
}

plot(NA,xlim=c(0,3),ylim=c(-20,0),xlab="log10(n)",ylab="log10(error)")
abline(h=0,col='gray')
n <- 50  # number of lines to plot
vals <- seq(from=0.2,to=0.4,len=n)
for(i in seq_along(vals)){
  points(log10(1:1000),log(abs(cumsum(f(1:1000,a=0.1,b=0.3, c=vals[i], d=0.3+vals[i])))),type="l",col=rainbow(n)[i])
}

## Draw the abutting case with a thick black line:
{
  i <- round(n/2)
  points(log10(1:1000),log(abs(cumsum(f(1:1000,a=0.1,b=0.3, c=vals[i], d=0.3+vals[i])))),type="l",col="black",lwd=5)
}

## Now a key:
ylow <- -20
yhigh <- -10
points(cbind(0.1,seq(from=yhigh,to=ylow,len=100)),pch=15,col=rainbow(100),cex=0.3)
two_segments <- function(y,a,b,c,d,xa=0.2,xb=0.7){
  segments(x0=xa+a*(xb-xa), x1=xa+b*(xb-xa),y0=y)
  segments(x0=xa+c*(xb-xa), x1=xa+d*(xb-xa),y0=y+0.03)
}

nn <- 20
for(i in 0:nn){
  two_segments(y=yhigh + i/nn*(ylow-yhigh), a=0.1, b=0.3, c=0.2 + (0.2)*i/nn, d=0.4 + (0.2)*i/nn)
}
@
\caption{First 1000 \label{plot3b} partial sums for $\left\langle
  f(b)-f(a),f(d)-f(c)\right\rangle$ for a variety of overlapping and
  nonoverlapping intervals shown in the colour key on the right; abutting
  case plotted in a thicker line.  See how the nonoverlapping cases approach
  zero according to a power law, while overlapping cases approach a small but
  finite nonzero value; the abutting case exhibits intermediate behaviour
  subject to rounding error} 
  \end{center}
\end{figure}
\clearpage

\subsection*{Conclusions}

In the study of Hilbert space, the crinkled arc is an interesting and
informative object.  


\bibliography{crinkled}

\appendix
\subsection*{Appendix: symbolic calculation}

Mathematica can evaluate equation~\ref{fbadc} symbolically; the idiom would be

\begin{verbatim}
Assuming[(a<b) && (b<c) && (c<d),  Sum[
     (Sin[(n-1/2)*Pi*b]-Sin[(n-1/2)*Pi*a])*
     (Sin[(n-1/2)*Pi*d]-Sin[(n-1/2)*Pi*c])/(Pi*(n-1/2)^2),
       {n,1,Infinity}
  ]]
\end{verbatim}

but this returns a very complicated and effectively unsimplifiable
expression involving a sum of 16 \verb+LerchPhi[]+ functions.

\end{document}
