## You're reading: Posts By Peter Rowlett

### 4. Prime-number Pattern

I’m slowly working to (sort of) recreate Martin Gardner’s cover images from Scientific American, the so-called Gardner’s Dozen.

This time it’s the turn of the March 1964 issue. In the article ‘The remarkable lore of the prime numbers’, later included as chapter 9 in Martin Gardner’s Sixth Book of Mathematical Games from Scientific American, Gardner describes how Stanislaw Ulam in a boring meeting doodled a grid of numbers, spiralling out, then circled the primes. “To his surprise the primes seemed to have an uncanny tendency to crowd into straight lines.” These Ulam sprials, discovered the year before, contain lines related to prime-generating functions, which I have written about recently.

I tried to write code for this that worked as the original doodle – starting in the middle with 1 and working from cell to cell outwards in an anticlockwise spiral.

To start, I set up a document like this. I’m going to use TikZ for the drawing, as usual, and etoolbox for some conditional logic.

\documentclass{standalone}
\usepackage{tikz}
\usepackage{etoolbox}
\begin{document}%

\end{document}

To move from cell to cell, I set some global counters to keep track of the current number (n), location, and the direction of the move to the next cell. The location is a pair of coordinates (x and y, initially (0,0)) and the direction of the move to the next cell is also a pair of values (xdir and ydir, initially (1,0)).

\newcounter{n}%
\setcounter{n}{1}%
\newcounter{x}%
\setcounter{x}{0}%
\newcounter{y}%
\setcounter{y}{0}%
\newcounter{xdir}%
\setcounter{xdir}{1}%
\newcounter{ydir}%
\setcounter{ydir}{0}%

The value of a counter called A is displayed in the document using a command \theA, but if the value is needed for a calculation then it is accessed using \value{A}. The % at the end of each line mean we ignore the whitespace, meaning the tikzpicture that we’re about to draw doesn’t have a load of blank spaces before it.

Next I drew a grid. I used scope to offset this by (0.5,0.5). This is so that I could place the numbers at integer coordinates even though the command grid puts its lines through integer points. Basically this means I don’t have to faff with lots of .5 values in the rest of the code.

\begin{tikzpicture}
\begin{scope}[shift={(0.5,0.5)}]
\draw (-5,-5) grid (5,5);
\end{scope}
\end{tikzpicture}

Next I drew a node at the centre of the grid to hold the number 1. This goes within the tikzpicture above, as do all the drawing commands.

\node at (0,0) {\then};

I’m now looking at a grid which contains the number 1. Not the most exciting, but it’s a start!

Drawing the other numbers is a matter of setting up some loops. After the initial 1, the doodle draws:

• one cell then turn
• one cell then turn
• two cells then turn
• two cells then turn

And so on until nine cells. First I set a loop on \i from 1 to 9 to represent that the length of the run of cells grows from 1 to 9. Within this, I put a loop on \k from 1 to 2 because, as noted above, each length of cells is repeated twice. Within this, I draw the actual cells using a loop on j which ranges from 1 to the current value of \i. These loops look like this:

\foreach \i in {1,...,9}{
\foreach \k in {1,2}{
\foreach \j in {1,...,\i}{

}
}
}

Within the inner loop, I first increase n.

\addtocounter{n}{1}

Then I move x and y to the next cell position. This means increasing x by xdir and y by ydir. I first use \pgfmathsetmacro to do the calculation and store the result in \x and \y, then use these values to update my x and y counters and to draw the new number. I use global counters in this way rather than the commands \x and \y directly because the values of \x and \y don’t persist between loops.

\pgfmathsetmacro{\x}{\value{x}+\value{xdir}};
\pgfmathsetmacro{\y}{\value{y}+\value{ydir}};
\setcounter{x}{\x};
\setcounter{y}{\y};
\node at (\x,\y) {\then};

At the moment, this will just keep drawing cells in a straight line. This is because I haven’t implemented the turns. This is a bit fiddly, but I was thinking of (xdir,ydir) as a vector pointing the way to the next cell. As such, the procession is:

• move to the right: (1,0);
• move to the cell above: (0,1);
• move to the left: (-1,0);
• move to the cell below: (0,-1).

I need to update these to the next direction outside the \j loop but inside the \k loop. From the procession above, I notice that if xdir is 0 in the current iteration, then ydir is going to be 0 in the next, and if xdir is currently non-zero then it is going to be 0 in the next iteration. In the cases where xdir is zero, if ydir is 1 then xdir becomes -1 and otherwise it becomes 1. Similarly, if xdir is non-zero then either xdir is 1 and ydir should change to 1 or else ydir should change to -1.

I implement this as a series of if statements using \ifnumequal from etoolbox. These are used to set the values of the counters xdir and ydir.

\ifnumequal{\value{xdir}}{0}{
\ifnumequal{\value{ydir}}{1}{
\setcounter{xdir}{-1}; % left
}{
\setcounter{xdir}{1}; % right
}
\setcounter{ydir}{0};
}{
\ifnumequal{\value{xdir}}{1}{
\setcounter{ydir}{1}; % up
}{
\setcounter{ydir}{-1}; % down
}
\setcounter{xdir}{0};
}

Now I’m looking at a grid that spirals numbers, but only up to 91.

The reason for this is that each length of cells drawn occurs twice until the last. Instead of going into two runs of 10 cells, the cover image stops at 100. To fix this I need to alter the \k loop so that it runs a third time when \i is 9. This is a bit fiddly, but you can see how I did it in the full code below.

The other important aspect of this diagram is that the primes are highlighted with red text and green diagonals. Let’s focus on the red text. Without wanting to write a prime number checker into my LaTeX, I figured I would do what I’d do if I were doodling this by hand – cross-reference with a list of primes.

I did this using commands from etoolbox. First, before my tikzpicture, I set up a command \col to hold the current colour (initially black), and a list of \primes.

\newcommand{\col}{black}%
\newcommand{\primes}{}%
\forcsvlist{\listadd\primes}{2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97}%

Now inside my \j loop, after incrementing the counter, I tested whether the current value of n (\then) is in the list of primes. If it is, then I set \col to red, and if not black.

\xifinlist{\then}{\primes}{\renewcommand{\col}{red}}{\renewcommand{\col}{black}}

Finally, I changed the command that draws each number to set the text to the colour stored in \col.

\node[\col] at (\x,\y) {\then};

Putting all this together, I’m now looking at a spiral up to 91 with primes marked.

From here, the rest is fairly cosmetic or similar to what we have already done. A bit of colouring, a twist to the \k loop adds the numbers 92-100, some conditional statements on the current direction draw the thick border to indicate the direction of the spiral, and a pair of lists identify which primes are crossed with one diagonal or the other.

The final result is this, an Ulam sprial to 100.

### Particularly mathematical Birthday Honours 2024

The UK Government have announced the new set of King’s Birthday Honours. Here’s our selection of particularly mathematical entries for this year. If you spot any more, let us know in the comments and we’ll add to the list.

• Philippa Bonay, Director, Operations, Office for National Statistics. Appointed OBE for Public and Charitable Services.
• Anne Davis, Professor of Mathematical Physics, University of Cambridge. Appointed OBE for services to Higher Education and to Scientific Research.
• Paul Fannon, Fellow, Christ’s College, Cambridge, and Volunteer, United Kingdom Mathematics Trust. Appointed OBE for services to Education.
• Ian Hall, Professor of Mathematical Epidemiology and Statistics, University of Manchester and Senior Principal Modeller, UK Health Security Agency. Appointed OBE for services to Public Health, to Epidemiology and to Adult Social Care, particularly during Covid-19.
• David Marshall, Lately Director of Census, Northern Ireland Statistics and Research Agency (now Northern Ireland chief electoral officer). Appointed OBE for services to Official Statistics and Census-taking in Northern Ireland.
• Bruno Reddy, Founder and Chief Executive Officer, Maths Circle, Ampthill, Bedfordshire, and creator of Times Tables Rock Stars. Appointed OBE for services to Education.
• Sam Rose, Deputy Director, Data and Analysis Division, Department for Transport. Appointed OBE for services to Advanced Analytics
• Matthew Woollard, Professor of Data Policy and Governance, UK Data Archive, University of Essex. Appointed OBE for services to Data Science
• George McMath, Lately Deputy Principal, Northern Ireland Statistics and Research Agency, Northern Ireland Civil Service. Appointed MBE for services to the Northern Ireland Census.

Get the full list from gov.uk. Spot anyone we’ve missed? Let us know in the comments.

### Prime-generating functions

A few weeks ago I heard someone casually refer to ‘that formula of Euler’s that generates primes’. I hadn’t heard of this, but it turns out that in 1772 Euler produced this formula:

$f(x) = x^2 + x + 41\text{.}$

Using this, $$f(0)=41$$, which is prime. $$f(1)=43$$, which is also prime. $$f(2)=47$$ is another prime. In fact this sequence of primes continues for an incredible forty integer inputs until $$f(40)=41^2$$. It might generate more primes for higher inputs, but what’s interesting here is the uninterrupted sequence of forty primes.

This got me wondering. Clearly $$f(0)$$ is prime because 41 is prime, so that much will work for any function

$f(x) = x^2 + x + p$

for prime $$p$$, since $$f(0)=0^2+0+p=p$$. Are there other values of $$p$$ that generate a sequence of primes? Are there any values of $$p$$ that generate longer sequences of primes?

I wrote some code to investigate this. Lately, I’ve taken to writing C++ when I need a bit of code, for practice, so I wrote this in C++.

I figured the cases where $$f(0)$$ is prime but $$f(1)$$ isn’t weren’t that interesting, since $$f(0)$$ is trivially prime. In fact, $$f(x)=x g(x)+p=p$$ when $$x=0$$ for any prime $$p$$, but saying so doesn’t seem worth the effort.

So I kept track of the primes $$p$$ whose functions $$f(x)=x^2+x+p$$ generate more than one prime, and the lengths of the sequences of primes generated by each of these. This produced a pair of integer sequences.

I put the primes that work into the OEIS and saw that I had generated a list of the smaller twin in each pair of twin primes. I was momentarily spooked by this, until I realised it was obvious. Since $$f(0)=p$$ and $$f(1)=1^2+1+p=p+2$$, any prime this works for will generate at least a twin prime pair $$p,p+2$$.

What about the lengths of the sequences of consecutive primes generated? The table below shows the sequences of consecutive primes generated for small values of $$p$$. Most primes that generate a sequence produce just two, and $$p=41$$ definitely stands out by generating forty.

I was pleased to see this sequence of lengths of primes generated was not in the OEIS. So I submitted it, and it is now, along with the code I wrote. (I discovered along the way that the version where sequences of length one are included was already in the database.)

Anyway, I amused myself by having some C++ code published, and by citing Euler in a mathematical work. Enjoy: A371896.

### 3. Graeco-Latin square

With the emphasis on occasionally, I’m occasionally working to (sort of) recreate Martin Gardner’s cover images from Scientific American, the so-called Gardner’s Dozen.

This time I’m looking at the cover image from the November 1959 issue. The column is ‘How three modern mathematicians disproved a celebrated conjecture of Leonhard Euler’, about the so-called Euler’s Spoilers, the story of three mathematicians – Parker, Bose and Shrikhande – who had disproved a conjecture of Euler’s about Latin squares. The column was reprinted as chapter 14 in his New Mathematical Diversions from Scientific American.

### Finite Group: update and free livestream

A few months ago a group of us launched a membership club, The Finite Group, which you can join!

A big update is the lineup — your membership now supports the work of and gives you access to content from mathematician and TikTok star Ayliean MacDonald, as well as Chalkdust’s Matthew Scroggs and The Aperiodical’s Katie Steckles and me. Membership gives you access to a chat community and monthly livestreams. For a taste of the livestreams, check out this π minute video!

The big news is that the next livestream will be free to view live online on 27th March from 5-6pm GMT. All four of us will be working through the recent ‘100 Mathematical Conventions Questions’ quiz that’s been dividing (a small subset of) the internet. The stream will be available live, and a recording will be available to members afterwards.

### ChatGPT and history of maths misconceptions

You know how loads of things in maths are named for the wrong person? In 1996, a fun quiz appeared in The Mathematical Gazette based on history of maths misconceptions. It contained a series of questions where the obvious answer is not correct, such as “Who discovered Cramer’s rule?”, “Did Pascal discover the Pascal triangle?” and “Who first published Simpson’s rule?”

I was looking for a demo to show my students that generative AI programs are not producing accurate knowledge when I thought of this quiz. I put its questions to ChatGPT to see how it did. The point of the exercise is that these systems just parrot back words from their training data without any concept of truth, so if the training data is full of misconceptions, so too will be the responses. But these are misconceptions from the 1990s, so how much influence will they have on the responses?

You can see how ChatGPT did when I gave it the quiz in a short, free to read, open access paper in the British Journal for the History of Mathematics: Generative AI and accuracy in the history of mathematics.

### Aperiodical News Roundup – January 2024

Here’s a round-up of some mathematical news stories not reported elsewhere on the site this month.

### Maths News

Hiroki Takizawa claims Othello is solved: perfect play leads to a draw. (via Lance Fortnow)

Stephen Wolfram has announced version 14 of Mathematica, which will be available immediately both on the desktop and in the cloud. The latest version has 6602 built-in functions, and is accompanied by significant documentation and online tutorials to help people learn how to use it.

A new mathematical modelling competition, open from 1st Feb, invites predictions for when cherry trees will blossom in five cities in the USA and Japan, with cash and prizes awarded for a compelling narrative and reproducible analysis containing any data and code used. (via IMAmaths on X)

Science is reporting that a group of mathematicians are producing “low-quality papers” that repeatedly reference their work, distorting citation metrics apparently in an attempt to raise their institution’s rankings. As a result of this practice,

publishing analytics company Clarivate has excluded the entire field of math from the most recent edition of its influential list of authors of highly cited papers, released in November 2023.

(via Nalini Joshi on Mastodon)

Claire Voisin has been awarded the Crafoord Prize in Mathematics by the Royal Swedish Academy of Sciences — the first woman to win this award in mathematics. (via European Mathematical Society on Mastodon)