A Study on Directionality in the Ulam Square with the Use of the Hough Transform
A version of the Hough transform in which the direction of the line is represented by a pair of co-prime numbers has been used to investigate the directional properties of the Ulam spiral. The method reveals the detailed information on the intensities of the lines which can be found in the square and on the numbers of primes contained in these lines. This makes it possible to make quantitative assessments related to the lines. The analysis, among others, confirms the known observation that one of the diagonal directions is more populated with lines than the other one. The results are compared to those made for a square containing randomly located points with a density close to that for the Ulam square of a corresponding size. Besides its randomness, such square also has a directional structure resulting from the square shape of the pixel lattice. This structure does not depend significantly on the size of the square. The analysis reveals that the directional structure of the Ulam square is both quantitatively and qualitatively different from that of a random square. Larger density of lines in the Ulam square along one of the diagonal directions in comparison to the other one is confirmed.
KeywordsUlam Square Spiral Directionality Random Hough transform
Since its discovery in 1963 , the Ulam spiral  called also prime spiral  gains much attention as the visual way to get insight into the domain of prime numbers. It seems that the geometric structures which have an important mathematical meaning are, among others, the diagonal lines. One of the observations was that there are more primes on one diagonal than the other. It seems that there are still discoveries to be made about the Ulam spiral (cf. , Section Why It’s Interesting).
A proper tool for detection and analysis of line segments in an image is the Hough transform (HT) in its version for lines. The Ulam square is not a typical image in which real-world objects are represented by means of a projection onto the camera sensor, which is an approximation in itself. Rather, it is a strictly defined mathematical object. The analysis of lines treated as mathematical objects with the HT was considered by Cyganski, Noel and Orr [7, 8]. They paid attention to the problem of all the digital straight lines possible to be represented in an image, being a digitization of a mathematical straight line crossing the image. Kiryati, Lindenbaum and Bruckstein  compared the digital and analog Hough transforms. They discussed the relation between the digital HT according to  and the conventional HTs which are analog in nature.
The lines present in the Ulam square are not the approximations of any actual lines. These lines are, however, the sequences of points having strictly specified ratios of coordinate increments. Therefore, in the case of our interest, the concept of the HT described in  is too complex. In the present paper we shall use the version of the Hough transform according to  in which the ratios of coordinate increments along the object to be detected have been directly used in the process of accumulating the evidence for the existence of lines.
The HT according to  has already been used in  to find long contiguous sequences of points which form segments of straight lines. In the present paper, however, we shall investigate the directional structure of the Ulam spiral. We shall make an attempt to answer two questions. First, to what extent in some of the directions there are more linear objects in the Ulam square than in the other ones. Second, what is the difference between the directional structure of the Ulam square and the square of corresponding size with randomly displaced points. The use of the method proposed will enable us to give quantitative answers to these questions.
The relation of the coordinates in the direction table and the angle \(\alpha \) can be seen in Fig. 3. Only some specific angles can be represented. This is in conformity with our interest in sequences of points for which the increments of coordinates are expressed by small integers.
After the accumulation process, in each element of the accumulator, which corresponds to a specific line characterized with the slope and the offset, as previously defined, the following data are stored: the number of voting pairs and the number of primes in this line, and the list of primes which lie on this line. For each prime in this list the following data are stored: its value, its index in the spiral, and its coordinates p, q. Each list can be easily sorted according to the chosen item in these data.
The accumulator can be analyzed with respect to such aspects like, for example, the directional structure of the Ulam spiral, the existence of lines with large numbers of primes, the contiguous strings of points representing primes in the square, etc.
3 Directionality – Selected Results
Before we go on to the results, one more issue needs consideration. In any of our experiments we consider an Ulam square having a specific size, limited by the memory of the computer used and the available time for calculations. Both these requirements do not seem to be crucial, due to that on the one hand very large memories are available now and on the other hand we have to make the calculations only once. However, at this stage we have tried to see if there is a variability in the results with the growing size of the square, or if the results have a tendency to stabilize above some size. As it will be seen further, for some of the characteristics of the directionality, the second case holds. Therefore, we have come to a conclusion that, for the problem of our interest, we can preform the calculations for the square of quite a moderate size of \(1001\times 1001\) points. It contains \(78\,650\) primes, where the largest one is \(1\,001\,989\).
3.1 Ulam Square
Let us check if the number of primes on lines in each direction reveals some information on the directionality. This is shown in Fig. 5. It can be seen that the directional structure of the square is not revealed in this plot.
In the plots of Figs. 6 and 7 is is clearly see that the horizontal, vertical and diagonal lines are the most populated in the Ulam square. It can also be seen that one of the diagonals has more representation that the other in both graphs. This is in conformity with the observations found in literature . These two plots will be used in the further analysis.
3.2 Random Square
In Figs. 9 and 10 the results for ten different realizations of the random square are compared to those of the Ulam square. Most of these realizations were taken for \(1001\times 1001\) pixels, as this size was considered reasonable for the case of the primes square. However, to see whether the properties depend on the size of the random square, two realizations were taken for size \(501\times 501\) and two for size \(2001\times 2001\) pixels. For each of the ten realizations, the results are very similar. This means that the directional structure of the random square is stable, besides that any particular realization differs in its details and that the size of the image changes.
In the plots of Figs. 9 and 10 it can be seen that the random squares exhibit the directional structure in which the horizontal, vertical and both diagonal lines are dominating above the lines in other directions and that the directions are represented by different numbers of voting pairs. This phenomenon does not significantly depend on the realization of the random process which gave rise to a particular image. As it could be expected, the horizontal direction is not favored versus the vertical one; similarly, one diagonal direction is not favored versus the other one.
On the contrary, in the Ulam square one diagonal direction is dominating over the other one. This is the most conspicuous difference. The pattern of other points for subsequent directions is also different from that for the random square.
4 Summary and Prospect
A version of the Hough transform proposed previously has been used to investigate the directional properties of the Ulam spiral. The method makes it possible to assess the difference in the intensities of lines related to subsequent directions in the quantitative way, due to that the data on the points related to the angles are available.
The measures of line intensities used here allowed us to show that one of the diagonal directions is more populated with lines than the other one. Such a phenomenon is absent in the random square, although in that square also some directionality is observed.
The proposed method gives the possibility to study other quantitative characteristics of the Ulam square .
- 1.Wikipedia: Ulam spiral — Wikipedia, The Free Encyclopedia (2016). https://en.wikipedia.org/w/index.php?title=Ulam_spiral&oldid=726734495. Accessed 20 June 2016
- 3.Weisstein, E.W.: Prime spiral. From MathWorld–A Wolfram Web Resource (2016). http://mathworld.wolfram.com/PrimeSpiral.html. Accessed 20 June 2016
- 4.Authors of the Prime Spiral chapter: Prime spiral (Ulam spiral). The Math Images Project (2016). http://mathforum.org/mathimages/index.php/Prime_spiral_(Ulam_spiral). Accessed 20 June 2016
- 5.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)Google Scholar
- 7.Cyganski, D., Noel, W.F., Orr, J.A.: Analytic Hough transform. In: Proceedings of SPIE. Sensing and Reconstruction of Three-Dimensional Objects and Scenes, vol. 1260, pp. 148–159 (1990). doi:10.1117/12.20013
- 8.Liu, Y., Cyganski, D., Vaz, R.F.: Efficient implementation of the analytic Hough transform for exact linear feature extraction. In: Proceedings of SPIE. Intelligent Robots and Computer Vision X: Algorithms and Techniques, vol. 1607, pp. 298–309 (1992). doi:10.1117/12.57109
- 9.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, Heidelberg (2016). doi:10.1007/978-3-319-46418-3_55
- 11.Chmielewski, L.J., Orwski, A.: Prime numbers in the Ulam dsquare (2016). www.lchmiel.pl/primes. Accessed 01 Aug 2016