## capacity exceeded…

Posted in Books, University life with tags , , , on April 23, 2015 by xi'an

A silly LaTeX error took me a few minutes too many to solve: I defined

\renewcommand\theta{\boldsymbol{\theta}}


which got me the error message

TeX capacity exceeded ,
sorry [ grouping levels =255].


that I understood as a recursive definition. So I instead pre-defined the new θ as

\newcommand\btheta{\boldsymbol{\theta}}
\renewcommand\theta\btheta


which did not work either… After google-ing the issue, I found this on-line LaTeX Wikibook that provided me with the solution:

\let\btheta{\boldsymbol{\theta}}
\renewcommand\theta\btheta


which worked. Of course, a global change of \theta into \btheta would have been much much faster to execute….

## some LaTeX tricks

Posted in Books, Kids, Statistics, University life with tags , , , , on November 21, 2014 by xi'an

Here are a few LaTeX tricks I learned or rediscovered when working on several papers the past week:

1. I am always forgetting how to make aligned equations with a single equation number, so I found this solution on the TeX forum of stackexchange, Namely use the equation environment and then an aligned environment inside. Or the split environment. But it does not always work…
2. Another frustrating black hole is how to deal with integral signs that do not adapt to the integrand. Too bad we cannot use \left\int, really! Another stackexchange question led me to the bigints package. Not perfect though.
3. Pierre Pudlo also showed me the commands \graphicspath{{dir1}{dir2}} and \DeclareGraphicsExtensions{.pdf,.png,.jpg} to avoid coding the entire path to each image and to put an order on the extension type, respectively. The second one is fairly handy when working on drafts. The first one does not seem to work with symbolic links, though…

## BibTool on the air

Posted in Books, Linux, Travel, University life with tags , , , , , , , , , , on October 23, 2014 by xi'an

Yesterday night, just before leaving for Coventry, I realised I had about 30 versions of my “mother of all .bib” bib file, spread over directories and with broken links with the original mother file… (I mean, I always create bib files in new directories by a hard link,

    ln ~/mother.bib

but they eventually and inexplicably end up with a life of their own!) So I decided a Spring clean-up was in order and installed BibTool on my Linux machine to gather all those versions into a new encompassing all-inclusive bib reference. I did not take advantage of the many possibilities of the program, written by Gerd Neugebauer, but it certainly solved my problem: once I realised I had to set the variates

check.double = on
check.double.delete = on
pass.comments = off

all I had to do was to call

bibtool -s -i ../*/*.bib -o mother.bib
bibtool -d -i mother.bib -o mother.bib
bibtool -s -i mother.bib -o mother.bib


to merge all bib file and then to get rid of the duplicated entries in mother.bib (the -d option commented out the duplicates and the second call with -s removed them). And to remove the duplicated definitions in the preamble of the file. This took me very little time in the RER train from Paris-Dauphine (where I taught this morning, having a hard time to make the students envision the empirical cdf as an average of Dirac masses!) to Roissy airport, in contrast with my pedestrian replacement of all stray siblings of the mother bib into new proper hard links, one by one. I am sure there is a bash command that could have done it in one line, but I spent instead my flight to Birmingham switching all existing bib files, one by one…

## unicode in LaTeX

Posted in Books, Linux, Statistics, University life with tags , , , , , , on October 9, 2014 by xi'an

As I was hurriedly trying to cram several ‘Og posts into a conference paper (!), I looked around for a way of including Unicode characters straight away. And found this solution on StackExchange:

\usepackage[mathletters]{ucs}
\usepackage[utf8x]{inputenc}

which just suited me fine!

## a weird beamer feature…

Posted in Books, Kids, Linux, R, Statistics, University life with tags , , , , , , , , , , , , on September 24, 2014 by xi'an

As I was preparing my slides for my third year undergraduate stat course, I got a weird error that got a search on the Web to unravel:

! Extra }, or forgotten \endgroup.
\endframe ->\egroup
\begingroup \def \@currenvir {frame}
l.23 \end{frame}
\begin{slide}
?


which was related with a fragile environment

\begin{frame}[fragile]
\frametitle{simulation in practice}
\begin{itemize}
\item For a given distribution $F$, call the corresponding
pseudo-random generator in an arbitrary computer language
\begin{verbatim}
> x=rnorm(10)
> x
[1] -0.021573 -1.134735  1.359812 -0.887579
[7] -0.749418  0.506298  0.835791  0.472144
\end{verbatim}
\item use the sample as a statistician would
\begin{verbatim}
> mean(x)
[1] 0.004892123
> var(x)
[1] 0.8034657
\end{verbatim}
to approximate quantities related with $F$
\end{itemize}
\end{frame}\begin{frame}


but not directly the verbatim part: the reason for the bug was that the \end{frame} command did not have a line by itself! Which is one rare occurrence where the carriage return has an impact in LaTeX, as far as I know… (The same bug appears when there is an indentation at the beginning of the line. Weird!) [Another annoying feature is wordpress turning > into &gt; in the sourcecode environment…]

## Le Monde puzzle [#872]

Posted in Books, Kids, Statistics, University life with tags , , , , , on June 28, 2014 by xi'an

An “mildly interesting” Le Monde mathematical puzzle that eventually had me running R code on a cluster:

Within the set {1,…,56}, take 12 values at random, x1,…,x12. Is it always possible to pick two pairs from those 12 balls such that their sums are equal?

Indeed, while exhaustive search cannot reach the size of the set,

fowler=function(i=1,pred=NULL){
pred=c(pred,i)
for (j in (1:N)[-pred]){
a=outer(c(pred,j),c(pred,j),"+")
if ((sum(duplicated(a[lower.tri(a)]))>0)){
val=FALSE
}else{
if (length(pred)==n-1){
print(c(pred,j))
val=TRUE
}else{
val=fowler(j,pred)}}
if (val) break()
}
return(val)
}
fowler(i=N,pred=1)


with N=35 being my upper limit (and n=9 the largest value inducing double sums), the (second) easiest verification goes by sampling as indicated and checking for duplicates.

mindup=66
for (t in 1:10^7){
#arguing that extremes should be included
x=c(1,56,sample(2:55,10))
A=outer(x,x,"+")
mindup=min(mindup,sum(duplicated(A[lower.tri(A)])))
if (mindup==0) break()}


The values of mindup obtained by running this code a few times are around 5, which means a certain likelihood of a positive answer to the above question…

This problem raises a much more interesting question, namely how to force simulations of those 12-uplets towards the most extreme values of the target function, from simulated annealing to cross-entropy to you-name-it… Here is my simulated annealing attempt:

target=function(x){
a=outer(x,x,"+")
return(sum(duplicated(a[lower.tri(a)])))}
beta=100
Nmo=N-1
nmt=n-2
nmo=n-1
x=sort(sample(2:Nmo,nmt))
cur=c(1,x,N)
tarcur=target(cur)
for (t in 1:10^6){
dex=sample(2:nmo,2)
prop=sort(c(cur[-dex],sample((2:Nmo)[-(cur-1)],2)))
tarprop=target(prop)
if (beta*log(runif(1))<tarprop -tarcur){
cur=prop;tarcur=tarprop}
beta=beta*.9999
if (tarcur==0) break()}


Apart from this integer programming exercise, a few items of relevance in this Le Monde Science & Medicine leaflet.  A portrait of Leslie Lamport for his Turing Prize (yes, the very same Leslie Lamport who created LaTeX!, and wrote this book which stood on most mathematicians’ bookshelves for decades, with the marginally annoying lion comics at the head of each chapter!). A tribune on an interesting book, The Beginning and the End, by Clément Vidal, discussing how to prepare for the end of the Universe by creating a collective mind. And the rise of biobanks…

## Le Monde puzzle [#849]

Posted in Books, Kids, R, Statistics with tags , , , , , on January 19, 2014 by xi'an

A straightforward Le Monde mathematical puzzle:

Find a pair (a,b) of integers such that a has an odd number d of digits larger than 2 and ab is written as 10d+1+10a+1. Find the smallest possible values of a and of b.

I ran the following R code

d=3
for (a in 10^(d-1):(10^d-1)){
c=10^(d+1)+10*a+1
if (a*trunc(c/a)==c)
print(c(a,c))}


which produced a=137 (and b=83) as the unique case. For d=4, I obtained a=9091 and b=21, for d=6, a=909091, and b=21, for d=7, a=5882353 and b=27, while for d=5, my code did not return any solution. While d=8 took too long to run, a prime factor decomposition of 10⁹+1 leads to (with the schoolmath R library)

> for (d in 3:10) print(c(d,prime.factor(10^(d+1)+1)))
[1]   3  73 137
[1]    4   11 9091
[1]    5  101 9901
[1]      6     11 909091
[1]       7      17 5882353
[1]     8     7    11    13    19 52579
[1]     9   101  3541 27961
[1]   10   11   11   23 4093 8779


which gives a=52631579 and b=29 for d=8 and also explains why there is no solution for d=5. The corresponding a has too many digits!

This issue of Le Monde Science&Médecine leaflet had more interesting entries, from one on “LaTeX as the lingua franca of mathematicians”—which presumably made little sense to any reader unfamiliar with LaTeX—to the use of “big data” tools (like news rover) to analyse data produce by the medias, to  yet another tribune of Marco Zito about the “five sigma” rule used in particle physics (and for the Higgs boson analysis)—with the reasonable comment that a large number of repetitions of an experiment is likely to exhibit unlikely events, and an also reasonable recommendation to support “reproduction experiments” that aim at repeating exceptional phenomena—, to a solution to puzzle #848—where the resolution is the same as mine’s, but mentions the principle of Dirichlet’s drawers to exclude the fact that all prices are different, a principle I had never heard off…