# Contiguous Line Segments in the Ulam Spiral: Experiments with Larger Numbers

• Leszek J. Chmielewski
• Maciej Janowicz
• Grzegorz Gawdzik
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 10245)

## Abstract

In our previous papers we have investigated the directional structure and the numbers of straight line segments in the Ulam spiral. Our tests were limited to primes up to $$25\,009\,991$$ due to memory limits. Now we have results for primes up to about $$10^9$$ for the previously used directional resolution, and for the previous maximum number but with greatly increased directional resolution. For the extended resolution, new long segments have been found, among them the first one with 14 points. For larger numbers and the previous resolution, the new segments having up to 13 points were found, but the longest one is still the one with 16 points. It was confirmed that the relation of the number of segments of various lengths to the corresponding number of primes for a given integer, for large numbers, is close to linear in the double logarithmic scale.

### Keywords

Ulam spiral Ulam square Prime numbers Line segments Number of segments Large numbers

## 1 Introduction

Studies on the set of prime numbers are important due to many reasons, including for example the design of ciphers. One of the ways through which this set can be investigated is the Ulam spiral [9]. It is a two-dimensional pattern formed by prime numbers distinguished in the set of natural numbers written down in a square grid as a spiral going from the center around to infinity [11]. This makes it possible to investigate some of the properties of this set with the use of the image processing methods. The Ulam spiral will be considered together with the square in which it is embedded, which we shall call the Ulam square. This square will be considered as an image composed of pixels, called also points.

There is a common opinion that the diagonals in the Ulam spiral are important, although the sources which can be found belong to the class of volatile publications [7, 8]. This drew our attention to the question on contiguous line segments within the Ulam square.

Our previous experience described in [2, 3, 5, 6] suggests that there is a gap in lengths of the set of continuous line segments. Up till now we have investigated the Ulam square of dimension up to $$5001 \times 5001$$ which corresponds to a largest prime equal to 25 009 991. The directions of segments considered were those possible to be expressed as a quotient of integers up to 10. Under these conditions there are numerous segments of lengths from 2 to 10 points, less than ten segments 11 and 12 points long, and single segments 13 and 16 points long. There are neither segments longer than 16 nor segments of lengths 14 and 15 points found.

Now we have extended the search to the Ulam square up to $$31623 \times 31623$$ which corresponds to the largest prime equal to $${1\,000\,014\,121} > 10^{9}$$ if the same directions as previously are considered. We will show in this paper that there are still no segments of 14 and 15 points and that the 16 point segment is the longest one. This means that there are longer segments neither on lines inclined by a multiple of $$45^\circ$$ nor on those with directions expressed by quotients of small integers. This can have some consequences for the research on prime numbers, although it is not clear yet in exactly which way.

We have also studied the segments with directions expressible by quotients of larger integers, up to 50. This was done for squares up to $$5001 \times 5001$$, as previously studied, due to the technical limitations we have at present. We will show here that under these conditions the 16 point segment is still the longest one, and there are still no segments of length 15. However, a first single segment of length 14 has been found. Also some new segments of other large length have been detected.

The next parts of this paper are organized as follows. In Sect. 2 we shall very briefly mention the method of finding line segments, described elsewhere in more detail. In Sect. 3 we shall present the results obtained for larger numbers, with the set of directions as previously considered. In Sect. 4 the results for an extended set of directions will be shown, but for numbers as those considered in previous papers. The paper will be concluded in Sect. 5.

## 2 Method in Brief

The method was described in detail in [2] and its main elements were repeated in [3, 5, 6], so here let us only provide the main functional information.

The central part of the Ulam spiral is shown in Fig. 1a. The origin of the coordinate system Opq is located in the center containing number 1. Let us denote the coordinates of the number in the Ulam square, say number five, as p(5) and q(5). Let us consider three points corresponding to numbers 23, 7, 19 which form a contiguous segment. Its slope can be described by the differences in coordinates between its ends: $$\varDelta {}p=p(19)-p(32)=2$$ by $$\varDelta {}q=q(19)-q(32)=2$$. Now let us pay attention to the table shown in Fig. 1b called the direction table denoted D, with elements $$D_{ij}$$. If we denote $$\varDelta {}p=i$$ and $$\varDelta {}q=j$$ we can see that this segment, inclined at the angle $$\alpha =-45^\circ$$, can be described, after reducing the directional vector from $$(-2,2)$$ to $$(-1,1)$$, by the point $$(i,j)=(-1,1)$$ in the direction table. Its offset can be described as q of its section with axis Oq, that is $$q(19)=-2$$. The dimensions of table $$D_{ij}$$ make it possible to represent slopes expressed by pairs $$i\in [0:N]$$ and $$j\in [-N,N]{\setminus }\{0\}$$. By example, let us consider points 23, 2, 13. They form a segment inclined by $$(i,j)=(2,1)$$, with offset $$q(2)=1$$. The points in this segment are the closest possible at this direction, although they are not neighbors in the normal sense. However, they are the closest possible at the direction considered; hence, the segment formed by them will be denoted as contiguous. The angle can take as many different values as is the number of black circles in Fig. 1b with thin lines.

The direction table can be used as the accumulator in the Hough transform for straight lines passing exactly through the points in the Ulam spiral. The neighborhood from which a second point is taken for each first point in the two-point Hough transform is related to the dimensions of $$D_{ij}$$ (with avoiding doubling the pairs). During the accumulation process, in each $$D_{ij}$$ a one-dimensional data structure is formed. For each vote the line offset and the locations of voting points are stored and the pairs and their primes are counted.

After the accumulation process the accumulator can be analyzed according to the need. Here, as it was in [3], we shall be interested in finding the numbers of contiguous segments of different lengths.

The object of our interest is well defined and is constant in time, so the calculations have to be carried out only once. However, let us remind after [5] that the complexity of the accumulation is $$O(PN^2)$$, where it is assumed that the square size is $$S\times {}S$$ and it contains $$P=\pi (S^2)$$ primes ($$\pi (\cdot )$$ is the prime counting function [10]). The complexity of the analysis for finding the segments is $$O(N^2S^2log(S))$$. For the largest squares analyzed up till now the time was several hours, but its considerable part was devoted to finding the primes within the square dimensions, for which we used a very simple procedure. Memory requirement is $$O(N^2S^2)$$ and this was the limiting factor in the calculations. We used a 64-bit machine with 64 GB of RAM, programmed single-threaded in GNU C.

In the calculations presented in the previous papers it was assumed $$N=10$$ or less, and the analyzed squares were up to $$S\times {}S=5001 \times 5001$$ containing $$1\,566\,540$$ primes, the largest of which was $$25\,009\,991$$. In the present paper we shall relax both limits, one at a time. The largest square we shall consider will be $$31623 \times 31623$$ which corresponds to the largest prime equal to $${1\,000\,014\,121} > 10^9$$. This is still very little in relation to the largest primes known at present, with the number of digits exceeding 20 millions [1]. However, a step of several orders of magnitude has been made, and next steps can be made should it be necessary.

## 3 Larger Numbers, Formerly Used Directions

For the direction table of dimensions $$[0,10]\times [-10,10]$$ as specified before, in [3] the squares of dimensions up to $$5001 \times 5001$$ were analyzed. Now we extend this dimension up to $$31623 \times 31623$$. In the graph in Fig. 2 the distribution of the numbers of segments versus their lengths is shown for the previously and newly investigated sizes of the Ulam square. The numbers of short segments grow together with the size of the square. This could have been expected due to that, informally speaking, in a larger square there are simply more points. However, the numbers of the longest segments increase only by a small difference, or even remain constant, as it is in the case of the globally longest segment found until now. For primes considered now, there are no segments of lengths 14 and 15, and the segment with 16 points remains single. A new 13 point segment was found among the numbers above $$6.6\times {}10^8$$.

Let us look now at the graphs of the numbers of segments versus the value of the largest prime number, and the number of prime numbers, as it was first done in [5], but with new data for larger primes added, in Fig. 3. What is interesting is that the tendency of the graphs to become a straight line for larger arguments starts to be seen also for the longest segments, like for example the 11 points segments, and also the 12 points ones, however less clearly. It is possible that for larger numbers also the 13 points segments could follow this tendency. Little can be said on the 16 points one, which is still single. The intriguing gap in length between the segments with 13 and 16 points stays up to the largest prime slightly over $$10^9$$.

The graphs with respect to the value of the largest prime are shown in Fig. 4. The linear tendency is conspicuous and it is followed for larger numbers of primes without change.

## 4 Larger Set of Directions, Formerly Used Numbers

The restriction of $$N=10$$ for the dimensions of the direction table can now be relaxed as more RAM is available. We have tested an array with $$N=50$$, which was possible if the size of the Ulam square $$S=5001$$ is maintained. This made it possible for the directions to be more numerous, but also for the subsequent points of the segments to be more remote from each other.

The graph with respect to the value of the largest prime (corresponding to Fig. 4 for direction table with $$N=10$$) is shown in Fig. 5. Several observations can be made.

The most apparent change is that there are three new long segments of 14 points. Two of them emerged near $$3\times 10^5$$, and the third one for the primes over $$10^6$$. The first two are shown in Fig. 6a, together with segment 16 for comparison of scale and range. In the new segments the distances between points are very long in comparison to the formerly found ones. Their directions are $$(39,-37)$$, (43, 33) for the segments visible in Fig. 6 and $$(47,-31)$$ for the one farther from the spiral center.

In Fig. 7 the segments with 13 points visible in a $$2001 \times 2001$$ square are shown. One of them was found with directions at $$N=10$$, the others were found with directions at $$N=50$$. As in the case of 14 points segments, in the newly found segments the distances between their points are larger than in those found previously.

Consequently, it should be noted that the gap between the segments with 13 and 16 points has been partly filled.
The last observation is that the close-to-linear shape of the graphs became less apparent in the left-hand side and the central part of the graphs. The linearity seems to hold for numbers over $$10^5$$, quite similarly as it was in the case of less directions. Extending the calculations to larger numbers could reveal the validity of the experimental asymptotic tendency in this case.

## 5 Conclusion

The Ulam spiral containing prime numbers up to slightly above $$10^9$$ was investigated from the point of view of the existence of contiguous straight line segments. This paper was a continuation of the previous works in which the Ulam square of size up to $$5001 \times 5001$$ were analyzed, for directions expressible by quotients of integers up to 10. In this paper we have studied the numbers in squares up to $$31623 \times 31623$$ which corresponds to the largest prime equal to $${1\,000\,014\,121} > 10^9$$, which is 40 times more than previously. Alternatively, square of the previous size was analyzed, but the directions extended to those expressible by quotients of integers up to 50.

For larger numbers it was confirmed that the longest segment has 16 points and that there are no segments of length 14 and 15. Previously, the segment with 13 points was single, but now another such segment has been found at the numbers above $$6.6\times {}10^8$$. For the extended directional resolution, new long segments have been found, among them the first one with 14 points. This partially fills the previously observed gap between the segments having 13 and 16 points.

For large numbers, it was confirmed that the relation of the number of segments of various lengths to the corresponding number of primes is close to linear in the double logarithmic scale. This holds for primes over $$10^5$$ and segments of lengths not larger than 11.

The data obtained in this and our other papers on the analysis of regularities in the Ulam spiral in a downloadable form can be found in the web page [4].

### References

1. 1.
Caldwell, C.K. (ed.): The Prime Pages (2016). primes.utm.edu. Accessed 15 Oct 2016
2. 2.
Chmielewski, L.J., Orłowski, A.: Hough transform for lines with slope defined by a pair of co-primes. Mach. Graph. Vis. 22(1/4), 17–25 (2013). mgv.wzim.sggw.pl/MGV22.html Google Scholar
3. 3.
Chmielewski, L.J., Orłowski, A.: Finding line segments in the Ulam square with the Hough transform. In: Chmielewski, L.J., Datta, A., Kozera, R., Wojciechowski, K. (eds.) ICCVG 2016. LNCS, vol. 9972, pp. 617–626. Springer, Cham (2016). doi:10.1007/978-3-319-46418-3_55
4. 4.
Chmielewski, L.J., Orłowski, A.: Prime numbers in the Ulam square (2016). www.lchmiel.pl/primes. Accessed 14 Oct 2016
5. 5.
Chmielewski, L.J., Orłowski, A., Gawdzik, G.: Segment counting versus prime counting in the Ulam square. In: Nguyen, N.T., Tojo, S., Nguyen, L.M., Trawiński, B. (eds.) ACIIDS 2017. LNCS, vol. 10192, pp. 227–236. Springer, Cham (2017). doi:10.1007/978-3-319-54430-4_22
6. 6.
Chmielewski, L.J., Orłowski, A., Janowicz, M.: A study on directionality in the Ulam square with the use of the Hough transform. In: Kobayashi, S., Piegat, A., Pejaś, J., El Fray, I., Kacprzyk, J. (eds.) ACS 2016. AISC, vol. 534, pp. 81–90. Springer, Cham (2017). doi:10.1007/978-3-319-48429-7_8
7. 7.
GeMir: Quadratic polynomials describe the diagonal lines in the Ulam-Spiral. Mathematics Stack Exchange, 15 July 2015. math.stackexchange.com/q/1347560. Accessed 28 Jan 2017
8. 8.
PrimeCrank: Ulam spiral explained (sort of...). Prime Numbers on barkerhugh.blogspot.com, 22 February 2012. barkerhugh.blogspot.com/2012_02_01_archive.html. Accessed 28 Jan 2017
9. 9.
Stein, M.L., Ulam, S.M., Wells, M.B.: A visual display of some properties of the distribution of primes. Am. Math. Mon. 71(5), 516–520 (1964). doi:10.2307/2312588
10. 10.
Weisstein, E.W.: Prime counting function. From MathWorld-A Wolfram Web Resource (2016). mathworld.wolfram.com/PrimeCountingFunction.html. Accessed 15 Oct 2016
11. 11.
Weisstein, E.W.: Prime spiral. From MathWorld-A Wolfram Web Resource (2016). mathworld.wolfram.com/PrimeSpiral.html. Accessed 15 Oct 2016

© Springer International Publishing AG 2017

## Authors and Affiliations

• Leszek J. Chmielewski
• 1
• Maciej Janowicz
• 1
• Grzegorz Gawdzik
• 1