# Quadratic polynomials describe the diagonal lines in the Ulam-Spiral

I'm trying to understand why is it possible to describe every diagonal line in the Ulam-Spiral with an quadratic polynomial $$2n\cdot(2n+b)+a = 4n^2 + 2nb +a$$ for $a, b \in \mathbb{N}$ and $n \in 0,1,\ldots$.

It seems to be true but why?

Wikipedia says: "The pattern also seems to appear even if the number at the center is not 1 (and can, in fact, be much larger than 1). This implies [WHY?] that there are many integer constants b and c such that the function: $4n^2+bn+c$ as $n$ counts up $\{1, 2, 3, ...\}$, a number of primes that is large by comparison with the proportion of primes among numbers of similar magnitude."

I can't find a source with a detailed explanation.

I found these equations:

So here is the solution:

\begin{align*} y_t - y_{t+1} - (y_{t+1} - y_{t+2}) &= 8\\ y_t - 2y_{t+1} + y_{t+2} &= 8\\ y_{t+2} - 2y_{t+1} + y_t &= 8 \end{align*}

1) We solve $y_{t+2} - 2y_{t+1} + y_t = 0.$

Let $y_t = A\beta^t$ \begin{align*} A\beta^{t+2} - 2A\beta^{t+1} + A\beta^t &= 0\\ A\beta^{t}\cdot (\beta^2 - 2\beta + 1) &= 0 \end{align*} $\beta^2 - 2\beta + 1 = 0$ has two identical solutions $\beta_{1,2} = 1$. So with $A_1$ and $A_2t$ we get $$y_t = A_1 + A_2t.$$

2) $1 + a_1 + a_2 = 0$ and $a_1 = -2$ so let $y_t = ct^2$ \begin{align*} c\cdot(t+2)^2 - 2c\cdot(t+1)^2 + ct^2 &= 8\\ c\cdot\big(t^2+4t+4 - 2\cdot(t^2+2t+1) + t^2\big) &= 8\\ c\cdot(t^2+4t+4 - 2t^2-4t-2 + t^2) &= 8\\ 2c &= 8\\ c &= 4 \end{align*} So $y_t = 4t^2$

3) The complete solution is $$y_t = 4t^2 + A_2t + A_1.$$

The "exclusion lines" seem to be interesting too: $$4n^2+n$$ $$4n^2+3n$$ $$4n^2+3n-1$$ $$4n^2-n$$ seem not to have any primes at all.

Useful website I found a bit late: http://ulamspiral.com

• There are some special diagonals which are for example $(2n)^2$ and $(2n+1)^2$ (these equations are very easy to obtain: the number of the tiles in a square) now you just need to shift them and obtain the equation of the other diagonals this for the first part,now If you want an explanation "why $4n^2+bn+c$ as $n$ counts up $\{1,2,3,...\}$ , a large number of primes", then there isn't one, it's an open problem.But it's an observation from the Ulam diagram and there is no proof for that. – Elaqqad Jul 2 '15 at 22:47
• @Elaqqad Could you be a little bit more precise? What do you mean saying "the number of the tiles in a square"? The number of tiles in a square is given by $n^2$ for side length $n$ ($2\times 2$ square contain $2^2$ tiles and so on), isn't that so? – GeMir Jul 7 '15 at 11:59

Note that the first "ring" of numbers has just 1 number in it, the next ring has $9-1=8$ numbers, then $25-9=16$, $49-25=24$, $81-49=32$, and so on. These numbers (aside from the first) are increasing by 8. When you start somewhere and go out along a diagonal, with each step you increase by 8 more than you did with the previous step. That is, the second difference of the sequence as you go out along a diagonal is a constant 8; $a_{n+2}-2a_{n+1}+a_n=8$. And the general solution of that difference equation ("recurrence relation") is $a_n=4n^2+bn+c$.

• Solving the difference equation, a second-order, linear, constant-coefficient, inhomogeneous recurrence relation, is standard stuff in introductory discrete math courses. You'll find the techniques in dozens of textbooks, all over the internet, and in many questions that have been posted to this website. Here are the notes I used, last time I taught this material: rutherglen.science.mq.edu.au/wchen/lndmfolder/dm16.pdf – Gerry Myerson Jul 8 '15 at 0:23
• But it's easier than all that. You've got a sequence going up by 8, so it's $b_n=b_0+8n$. Then you've got a sequence going up by $b_n$, so it's $a_n=a_0+\sum_1^n(b_0+8k)$. And you know $\sum_1^nk=k(k+1)/2$. – Gerry Myerson Jul 8 '15 at 0:26
• So, are you happy now with the answer? Any other questions about it, GeMir? – Gerry Myerson Jul 9 '15 at 12:27
• I'm not really sure if it's enough to say "the difference of rings lengths is always 8". I mean, it's an observation and there is no reason for this to change but it doesn't look like a "bulletproof" proof to me :) – GeMir Jul 9 '15 at 12:46
• Then refine it into a watertight proof. I've given you a good start. I encourage you to fill in any missing details on your own. Once you have something that's watertight, you can even post it here, as an answer to your own question. That's encouraged on this website. – Gerry Myerson Jul 10 '15 at 1:41

One of the most important questions here seems to be why some quadratic polynomials are richer in primes than others. Because the primes are recursive, prime-rich functions tend to not produce multiples of small primes. This can be derived using modular arithmetic. For instance, Euler's function (n^2 + n + 41) begins with 41 and then has term-to-term differences of all the even numbers. 2, 4, 6, ...

The remainder modulo 7 thus starts at 6, and cycles like this: 6, 1, 5, 4, 5, 1, 6, 6, 1, 5, 4, 5, .... and this proves that Euler's equation never yields a multiple of 7 (it would have a remainder of 0).

I have used sieving and other techniques to discover quadratic equations with very few solutions modulo small primes. Significantly denser than Euler's formula is n^2 + n + 247757. Equations of the type n^2 + n + C are split on the Ulam Spiral - one diagonal line is for odd n and the other for even n.

Dario Alpern has an applet for the Ulam Spiral - try entering 247757 into the starting number here and zooming out:

https://www.alpertron.com.ar/ULAM.HTM