Next Article in Journal
A Study on the Conductivity and Infrared Spectroscopy of Elastic Polymer Composite Materials
Previous Article in Journal
Characterization and Finite Element Modeling of Microperforated Titanium Grade 2
Previous Article in Special Issue
Advances in the Neural Network Quantization: A Comprehensive Review
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Some Properties and Algorithms for Twin Primes

by
Gerardo Iovane
1,*,
Patrizia Di Gironimo
2,
Elmo Benedetto
1 and
Vittorio D’Alfonso
1
1
Department of Computer Science, University of Salerno, via Giovanni Paolo II, 132, 84084 Fisciano, SA, Italy
2
Department of Mathematics, University of Salerno, via Giovanni Paolo II, 132, 84084 Fisciano, SA, Italy
*
Author to whom correspondence should be addressed.
Appl. Sci. 2024, 14(17), 7902; https://doi.org/10.3390/app14177902
Submission received: 3 August 2024 / Revised: 24 August 2024 / Accepted: 27 August 2024 / Published: 5 September 2024

Abstract

:
In this article, we study some new properties of twin primes and algorithms for their generation. We find the necessary conditions to generate a pair of twins. These conditions seem to indicate that the conjecture is true, namely, there are infinitely many twin primes. Furthermore, we developed some algorithms that are very useful from a computer science point of view, which can be applied in cryptography and data encryption.

1. Introduction

Arithmetic is the queen of Mathematics and prime numbers are the building blocks of Arithmetic. It is well known that every natural composed number greater than 1 can be represented uniquely as a product of prime numbers, up to the order of the factors. The physical world is founded through a finite number of bricks, namely quarks, leptons and bosons, while the Arithmetic world is built with an infinite number of bricks. Indeed, Euclid, in his “Elements”, proved in a wonderfully simple way that prime numbers are infinite. How they are distributed within natural numbers is not very easy to understand [1,2,3,4]. The distribution is so complex that it seems random even if, from a theoretical point of view, we can say that it is not [5,6,7]. Indeed, Wilson’s theorem tells us that n > 1 is a prime number if and only if n 1 ! 1 m o d n . The distribution of prime numbers is not only of mathematical interest but also, for example, in the cryptographic and computer science field [8,9,10]. The aim of this paper is, instead, to use twin primes to apply them in the cryptography framework. The mathematical literature on prime numbers is so vast that it is not easy to report a complete bibliography [11,12,13,14]. Another unsolved property concerns the number of twin primes. The twin prime conjecture assumes that they are infinite, but there is still no proof of it officially accepted by mathematicians [15,16,17,18,19]. We know that the sum of the reciprocals does not diverge but tends towards the so-called Brun’s constant [20]
B 2 = 1 3 + 1 5 + 1 5 + 1 7 + 1 11 + 1 13 + . . 1.902160578
This fact, unfortunately, does not allow us to deduce anything about the number of twins. In fact, as is well known, a finite sum can be obtained either with an infinite number of terms or with a finite number.

2. Twin Primes

This section is devoted to finding a method to generate twin primes. We start to observe that, except for 2 , all prime numbers are odd numbers. For this reason, a prime number is necessarily of the type
2 k + 1 ,   k N
or
2 k 1 ,   k N 1 .
From the previous relations (2) and (3), we have the following Table 1.
It is trivial to observe, in the previous table, that there are values of k to which a pair of twins is associated. This occurs for values of k that generate a prime number in both columns. For example, for each value of k equal to 2, 3, 6, 9, 15, we achieve twin primes. We do not know by what rule k varies to return a prime number in the two columns, but we can understand when it generates a composite number. Recalling that the composite numbers are the product of two odd numbers different from 1, we have that the composite numbers of (2) are generated by the following product
2 x + 1 2 y + 1 = 2 2 x y + x + y + 1 ,     x , y N .
It is also possible to consider 2 x 1 2 y 1 with x , y N 1 achieving the same result. Therefore, we obtain a prime number in the second column, if and only if k 2 x y + x + y . Instead, from (4), we deduce that a composite odd number of the second column of the table is generated by the following values
k = 2 x y + x + y ,     x , y N .
Now, we consider x as a row and y as a column of a matrix. If x = 1 , from (5) we have
k = 3 y + 1 ,     y N .
Therefore, in the first row we have 4, 7, 10, 13, … and so on. If x = 2 , the relation (5) is
k = 5 y + 2 ,     y N .
Therefore, in the second row we have 7, 12, 17, 22, … and so on. It is easy to verify that the third row is k = 7 y + 3 , the fourth is k = 9 y + 4 and so on. In conclusion, we can write the following infinite matrix
A = 4 7 10 13 16 19 22 25 28 31 34 7 12 17 22 27 32 37 42 47 52 57 10 17 24 31 38 45 52 59 66 73 80 13 22 31 40 49 58 67 76 85 94 103 16 27 38 49 60 71 82 93 104 115 126 19 32 45 58 71 84 97 110 123 136 149
All numbers that are not in A correspond to values of k which, when substituted in 2 k + 1 , give us a prime number. They are infinite in number since there are infinitely many primes. Now, with the same reasoning, we deduce the law that generates composite odd numbers in the first column of the table. Indeed, the composite numbers will be
2 x 1 2 y + 1 = 2 2 x y + x y 1 ,     x N 1 ,     y N .
Therefore, we obtain a prime number, if and only if k 2 x y + x y . We obtain a composite odd number if
k = 2 x y + x y ,                   x , y N .
Like before, we built a matrix with x as row and y as column. If x = 2 , the relation (8) becomes
k = 3 y + 2 ,                   y N ,
achieving the sequence 5, 8, 11, 14, … and so on. If x = 3 , we have
k = 5 y + 3 ,                   y N ,
obtaining the sequence 8, 13, 18, 23, … and so on. It is easy to verify that the third row is k = 7 y + 4 , the fourth is k = 9 y + 5 . In conclusion, we can write the following infinite matrix
B = 5 8 11 14 17 20 23 26 29 32 35 8 13 18 23 28 33 38 43 48 53 58 11 18 25 32 39 46 53 60 67 74 81 14 23 32 41 50 59 68 77 86 95 104 17 28 39 50 61 72 83 94 105 116 127 20 33 46 59 72 85 98 111 124 137 150
All numbers that are not in B correspond to values of k which, when substituted in 2 k 1 , give us a prime number. They are infinite in number since there are infinitely many primes. In summary, the values of k which are in (6) but not in (9) (as for example 4) generate a prime in 2 k 1 and a composite number in 2 k + 1 . The values which are in (9) but not in (6) (as for example 5) generate, instead, a composite number in 2 k 1 and a prime number in 2 k + 1 . The values of k that are in both sequences (as for example 17) generate composite numbers in both 2 k 1 and 2 k + 1 . Finally, there are values of k which are neither in (6) nor in (9). These values of k generate prime numbers in both columns of the table and, therefore, generate twins. To understand how many twin primes there are, we must find how many numbers are missing in the union of (6) and (9). Since we are interested in twin primes and not prime numbers, we merge the matrices (6) and (9) achieving the following matrix, which will allow us to identify twin prime numbers
C = 4 5 7 8 10 11 13 14 16 17 19 7 8 12 13 17 18 22 23 27 28 32 10 11 17 18 24 25 31 32 38 39 45 13 14 22 23 31 32 40 41 49 50 58 16 17 27 28 38 39 49 50 60 61 71 19 20 32 33 45 46 58 59 71 72 84
Indeed, any number that does not fit in C (as for example 6) corresponds to a value of k which gives us a pair of twins. Let us call r n the complement rows. In other words
r 1 = 1 , 2 , 3 , 6 , 9 , 12 , 15 , 18 , 21 , 24 , 27 , 30 , 33 , 36 , 39 , 42 , 45 , 48 , 51 , 54 , 57 , 60 , 63 , 66 , 69 , 72 , 75 , 78 , . r 2 = 1 , 2 , 3 , 4 , 5 , 6 , 9 , 10 , 11 , 14 , 15 , 16 , 19 , 20 , 21 , 24 , 25 , 26 , 29 , 30 , 31 , 34 , 35 , 36 , 39 , 40 , 41 , 44 , . . r 3 = 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 12 , 13 , 14 , 15 , 16 , 19 , 20 , 21 , 22 , 23 , 26 , 27 , 28 , 29 , 30 , . . r 4 = 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 24 , . . r 5 = 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 18 , 19 , 20 , 21 , 22 , 23 , 24 , 25 , 26 , 29 , . . r 6 = 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 21 , 22 , 23 , 24 , 25 , 26 , 27 , 28 , 29 , 30 , 31 , . . .
If k is a natural number with
k n = 1 r n
then 2 k 1 and 2 k + 1 are twin primes. We can write the twin prime conjecture in the following equivalent form
Twin Prime Conjecture.
Twin primes are infinite in number if and only if  n = 1 r n = N ,  where the vertical bar on each side is the cardinality.
First of all, we observe that r 1 , except 2, only has multiples of 3. Therefore, thanks to relation (11), for k to belong to the intersection of all lines, it must have a value that is a multiple of 3. Otherwise, from the definition of intersection between sets, it would not verify (11). In other words, the values of k that generate twins are necessarily multiples of 3. If one wants to reduce the computational cost, it is possible also to observe that, by construction, the row r 2 cannot have multiples of three which have the last digit equal to 2,3,7,8. Therefore, we have that a necessary condition for k to generate a pair of twins is that it is a multiple of three with the last digit equal to 0, 1, 4, 5, 6, 9. In [21], we verified the validity of the second condition for the first 10⁴ pairs of twins. It is possible to note that the n t h multiple of three is certainly present from r n 1 onwards and, therefore, the rows to be checked are from r 2 to r n 2 . Indeed, the generic row r n has the first numbers from 1 to 3 n , it does not have the numbers 3 n + 1 and 3 n + 2 and then has 2 n 1 consecutive numbers starting from 3 n + 3 ; successively it does not have two numbers and so on. Obviously, since it is not possible to control for infinite numbers, it is necessary to find a new strategy. Let us observe that
r 1 = 1 2 3 n
r 2 = 1 2 3 5 n 1 5 n 5 n + 1
r 3 = 1 2 3 4 7 n 2 7 n 1 7 n 7 n + 1 7 n + 2
r 4 = 1 2 3 4 5 9 n 3 9 n 2 9 n 1 9 n 9 n + 1 9 n + 2 9 n + 3
r n = i = 1 n + 1 i i = 1 n 1 2 i + 1 n ± γ i 1 , γ i 1 = i 1 , i = n 1 ,   n N .
Definition. 
Given the sequence r i , we call the first hole of r i and denote it by r ˙ i the first missing element so that r i does not coincide with ℕ.
Theorem of the localizations of the first hole.
Given the sequence  r n , we have that  r ˙ n = 3 n + 1   n N .
Proof. 
We want to show that r ˙ n + 1 = 3 + r ˙ n . Let
P n : r ˙ n = 3 n + 1 .
The base case
P 1 = r ˙ 1 = 4
is true, as you can verify. For the inductive step, we assume that P n is true for some integer n 1 and use this to prove that P n + 1 is true. We have that
P n + 1 = 3 n + 1 + 1 = 3 n + 1 + 3 = r ˙ n + 3 .
Then, we may conclude that P n is true for all integers n 1 .
It is easy to deduce the following result.
Corollary. 
For the sequences  r i  is valid that  lim n + r n = N .
Proof. 
From the theorem of the localizations of the first hole, we have that r ˙ n + 1 = 3 + r ˙ n   n N . Therefore,
lim n + r ˙ n = lim n + 3 n + 1 = +
and this means that r n N .
Definition. 
We define the jump extension  r ˙ n e  as the number of missing elements in  r n  between two successive subsequences starting from  r ˙ n .  That is
r ˙ n e = 2 k n + 1 m + n 1 2 k n + 1 m n 1 ,   n N .
Definition. 
We call the set of jumps for level  n  the set  r n j  defined as
r n j = N / r n .
For example, r 1 j = 4 , 5 , 7 , 8 , 10 , 11 , .
Definition. 
We define jump size  r ˙ n s  the distance between a subsequence  r n  and its successive. In other words, the distance between one hole and the successive corresponding one
r ˙ n s = 2 k n + 1 m + n 1 + 4 2 k n + 1 m n 1 + 1 .
We observe that the jump size of r 1 is 3. In fact, r ˙ 1 s = 7 4 = 10 7 = = 3 . Instead, for r 2 is 5. Indeed, r ˙ 2 s = 12 7 = 5 . From (12) it is possible to verify that the following is valid
Theorem of the invariance of the jump extension.
The jump extension  r ˙ n e  is invariant for each  n  and it is equal to 3, then there are two missing successive elements in  r n  for each jump size.
Proof. 
As a direct consequence of (12), we have that r n is made up of two types of terms, and that is, singletons i and subsets centered in 2 k n + 1 m with subsets from 2 k n + 1 m n 1 to 2 k n + 1 m + n 1 . The case n = 1 is trivial. Indeed,  r 1 = 1 2 2 k 1 + 1 m ,   m N , k 1 = 1 = 1 , 2 , 3 , 6 , 9 , .
Then, by using (13) we have
r ˙ 1 e = 6 3 = 9 6 = = 3 .
For this reason, there are two missing elements between two successive subsequences. With the same reasoning, we can write
r ˙ n e = 2 k n + 1 m + 1 n 1 2 k n + 1 m + n 1 = 2 k n + 1 2 n 1 .
The element k n at the nth level coincides with the value of n and we have
r ˙ n e = 2 n + 1 2 n + 2 = 3 .
Therefore, there are two missing elements between two successive subsequences. □
The following theorem characterizes the jump size.
Theorem of the jump size.
The jump size
r ˙ n s = 2 n + 1
and, therefore, is strictly increasing.
Proof. 
The truth of this proposition follows immediately from the structure (12) of r n . Indeed, we see that it is made up of the union of n + 1 singletons and 2 n 1 subsets of the type 2 k n + 1 m ± γ with γ = 0 , . . , n 1 . If 2 k n + 1 m = 2 n + 1 m is the central term, as γ varies, there will be n 1 subsets 2 k n + 1 m + γ and n 1 subsets 2 k n + 1 m γ . Thus, they, with the addition of the central term, are in total 2 n 1 . The difference between the two following holes is given from 2 n 1 by adding the two holes, that is 2 n 1 + 2 = 2 n + 1 as we would prove. In addition, for the symmetries of the structure, the same result is obtained by making the difference between the two following centroids i . e   2 k n + 1 m for each subset. For example, we have c 2 r 1 c 1 r 1 = 6 3 , where c i r j is the i-th centroid of r j . Moreover, c 2 r 2 c 1 r 2 = 6 ,   c 2 r 3 c 1 r 3 = 7 , etc. Finally, from (14), we deduce that r ˙ n s is an increasing function. □
Now, we deduce the following property.
Remark. 
By observing that  r ˙ n s  is strictly increasing, the holes will be increasingly rarer. In other words, in  r 1  we have that the distance between holes is 3, in  r 2  is 5 and so on. This means that as you progress with the lines there are fewer and fewer holes. Therefore,  r n N  if  n .
Corollary. 
The rows  r n ,   n N ,  are made up of a number of subsets equal to  3 n .
Proof. 
It is possible to note, from (12), that each r n is made up of a number of subsets equal to 3 n . Indeed, we have n + 1 singleton and 2 n 1 of the type 2 k n + 1 m ± γ . Therefore, we have n + 1 + 2 n 1 = 3 n .

3. Smart Algorithm for Finding Twin Primes

In this section, we develop an algorithm using the definition of twin primes, i.e., p = q + 2 with p and q prime numbers, in a way that is easier from a computational point of view. We have seen that, once k is fixed, two numbers p and q are twins if they are of the type p = 2 k 1 and q = 2 k + 1 with k i = 1 r i . As we have seen, from the first and second condition, we deduce that a necessary condition for k to generate a pair of twins is that it is a multiple of 3 with the last digit equal to 0, 1, 4, 5, 6, 9. Condition (11), therefore, can be simplified in order to obtain an effective algorithm. Indeed, rather than considering the infinite intersection, it will be sufficient to stop at a certain r j to check whether k ~ generates a pair of twins. This is possible because, if k ~ is contained in the first r j , it will certainly also belong to all the subsequent ones. Indeed, it is possible to note that the nth multiple of 3 is certainly present from r n 1 onwards and, therefore, the rows to be checked are from r 2 to r n 2 . The determination of j is obtained, as an immediate consequence of (12), in the following way
j m a x = k ~ 3 1 .
Furthermore, the maximum column m of each row r i can be determined by
m m a x = k ~ 3
by using the condition
m m a x = k ~ 5
where the symbol [a] means the biggest integer smaller than a.
Thanks to these conditions, we can write relation (11) as
k n = 1 j m a x r i
where r i ,   m m m a x . This twin prime number search algorithm can be further optimized by choosing m m a x = f i . In particular, we have that
m m a x i = k ~ 2 i + 1   k i N , r i .
In this way, instead of considering j m a x · m m a x elements we will obtain a smaller set of variable length m = m m i n i . Let us analyze the Algorithm 1:
Algorithms 1 Algorithm for finding and verifying the twin prime generator k ~
(1)
Accept input k ~
(2)
Compute j m a x following (15)
(3)
Once i is fixed, calculate m m a x i through the relation (19)
(4)
If k m m a x i = k ~ ,
-
increase i
-
repeat (4)
If k m m a x i < k ~ ,
-
calculate k m m a x i + 1 until it is greater than or equal to k ~
-
if k m m a x i + r = k ~ then increase i
-
if k m m a x i + r > k ~ then k ~ does not generate twins
If k m m a x i > k ~ ,
-
calculate k m m a x i 1 until it is minor than or equal to k ~
-
if k m m a x i r = k ~ then increase i
-
k m m a x i r < k ~ then k ~ does not generate twins
(5)
If i = j m a x , calculate, save and display k ~ , 2 k ~ 1 , 2 k ~ + 1 , # ( k )
where #( k ) is the total number of analyzed k .
The advantage of this smart algorithm compared to traditional algorithms is that the latter would generate a matrix r i m with at least j m a x · m m a x elements. Instead, the algorithm just presented, calculates only some elements of r i m . In particular, for each row, with 1 i j m a x , it calculates only the element k in column m m a x and possibly its neighbors. Below we show a conceptual scheme of what was said
r i j = . . . . . . . . .
There are many classic sieve algorithms and they play an important role in finding prime numbers. These classical algorithms have applications in many contexts including cryptography. For example, we can report some important sieves such as sieve of Eratosthenes, linear sieve, sieve of Sundaram, sieve of Atkin, sieve of Sorenson, segmented sieve of Eratosthenes with Wheel factorization [22,23,24,25].
The experiments conducted concerned 1 k ~ 10 10 . Below, we report the comparison Table 2.
As shown in Table 2, the classical algorithm requires the generation of all matrix cells, which leads to a significantly higher computational burden. In contrast, our smart algorithm optimizes the process by intelligently navigating through the matrix without needing to construct every cell. This approach drastically reduces the number of operations required, especially as k ~   increases. The efficiency gains are particularly evident at higher values of k ~ , where the smart algorithm demonstrates a reduction in computational load by several orders of magnitude compared to the classical approach.
Figure 1 shows, as k ~ varies, the curve of k calculated with both the traditional and the smart algorithms. The successive figure shows, as k ~ varies, the useful fraction graph of k calculated with respect to j m a x · m m a x and that is
# ( k ) j m a x · m m a x .
This comparison is made between the traditional algorithm and the smart algorithm, demonstrating the computational efficiency of the smart algorithm in reducing the number of operations required as k increases. The logarithmic scale on both axes emphasizes the substantial difference in performance between the two methods, with the smart algorithm consistently requiring fewer computations.
Furthermore, it shows the saved fraction which is
1 # ( k ) j m a x · m m a x
The graph in Figure 2 depicts as k varies, highlighting the proportion of computational effort saved by the smart algorithm compared to the traditional approach. As k increases, the smart algorithm demonstrates a significant reduction in computational complexity, effectively illustrating the efficiency gains achieved by avoiding unnecessary calculations. The logarithmic scale accentuates how the savings become more pronounced for larger values of k.
The algorithm exhibits a time complexity of O(k) relative to the parameter k. This linear complexity is highly efficient, especially considering that it avoids the explicit construction of a matrix, which would likely result in a higher computational cost, potentially O(k2) or greater depending on the matrix dimensions involved. The approach taken is therefore well-optimized for the problem at hand, balancing computational efficiency with the necessity of accurately simulating the matrix traversal process. This makes the algorithm particularly suitable for scenarios where memory usage and processing time are critical considerations.
Theorem. 
From the twin matrix, we can extract infinite sequences.
Proof. 
We start by writing
r 1 = 1 2 3 n = 1 2 a 1
with a 1 = 2 k 1 + 1 n n N and k 1 = 1 .
r 2 = 1 2 3 5 n 1 5 n 5 n + 1 = 1 2 3 a 2 1 a 2 a 2 + 1
with a 2 = 2 k 2 + 1 n n N and k 2 = 2 .
r 3 = 1 2 3 4 a 3 2 a 3 1 a 3 a 3 + 1 a 3 + 2
with a 3 = 2 k 3 + 1 n n N and k 3 = 3 and so on.
Therefore, we have
a m r m m N   with   a m = 2 k m + 1 n n N   and   k m = m .
Now, from the sequence a 1 = 3 n 1 = 2 k 1 + 1 n 1   n 1 N and k 1 = 1 , we can consider the subsequence
a ~ 2 = 3 n 1 n 1 = a 2 = 2 k 1 + 1 2 k 2 + 1 n 2   n 2 N , k 1 = 1 , k 2 = 2 .
From a ~ 2 we can consider the subsequence
a ~ 3 = 3 · 5 n 2 n 2 = a ~ 2 = 2 k 1 + 1 2 k 2 + 1 2 k 3 + 1 n 3   n 3 N , k 1 = 1 , k 2 = 2 ,   k 3 = 3 .
Proceeding in this way, we obtain
a ~ w = i = 1 w 2 k i + 1 n   n N , k i = i .
As they are defined, we have
a ~ w i = 1 w r i ,   w N
and, being a subsequence,
a ~ w = N ,   w N .
Ultimately,
lim w a ~ w = a ~ i = 1 r i
with
a ~ = N
The previous theorem seems to indicate that the twin conjecture is true which is that there are infinite pairs of twins.

4. Another Algorithm for Twin Primes

In Appendix A Section [1], we start by writing the following Algorithm 2 for twin primes:
Algorithms 2 Algorithm for twin primes
(1)
Start with a list of initial known primes, P = {2,3,5}, if the list is empty
(2)
Define the initial generator value G and the generator index I.
(3)
Compute the next generator value G n e x t using the current generator G and the next prime in the list P
G n e x t = G × G I + 1
(4)
Construct a set R of primes such that p P and p 2 < G n e x t
(5)
Generate a new list of potential primes:
-
Generate a set F of potential new primes using the following families:
-
From existing primes:
-
For each p P and p P i , calculate potential primes:
  • For j = 1 , 2 : F = G × j p i f ( G × j p < G n e x t )
-
From previously removed numbers:
-
For each r R , calculate potential primes:
  • For j = 1 , 2 : F = G × j r i f ( G × j r < G n e x t )
-
With adjustments of −1 and +1:
F = G × j 1
(6)
Optimize the list of potential primes:
-
Remove numbers from F that are multiples of any prime in R
F = F f F p R : f   m o d   p = 0
(7)
Merge the optimized list of potential primes into the main list of known primes
(8)
Clean the list of known primes to remove any invalid entries
(9)
Repeat the process with updated parameters to continue generating primes.
We generate a total of 896.062 pairs of twin prime numbers as in Table 3.
Below in Figure 3, we report the graph that relates the prime numbers generated to the time spent generating them, where the prime generated scale is multiplied to 1 × 107.
The function presents a logarithmic behavior, which could be an excellent field of application for a Polynomial Regression in search of a possible Fit. The following work is performed in Python in a Jupyter-lab environment (the details are in Appendix A Section [2]).
Following a series of trials, as in Figure 4 we found that the level 15 configuration emerged as the most optimal and, in Appendix A Section [3], we proceed to generate the actual model by exploiting the degree just identified.
To do this, we use, in the following application, three evaluation systems, that is MSE, RMSE, and R2 to obtain the following output
R2: 0.9994752721646499
MSE: 1,831,498,334.0579565
RMSE: 42,796.00838931075
Base model MSE (average): 4,087,907,127,997.419
The polynomial regression model is better than the baseline model.

5. Conclusions

In this paper, we described some new properties of twin primes. Since a prime number is necessarily of the type 2 k 1 and 2 k + 1 , we described some necessary conditions for k to generate twin primes. We built a matrix and by studying its rows we have proved some of their properties. In addition, we developed a smart algorithm to find twin primes and to confirm the twin primes’ conjecture in a very efficient way.

Author Contributions

The authors contribute equally for all the activities. All authors have read and agreed to the published version of the manuscript.

Funding

This research received no external funding.

Informed Consent Statement

Not applicable.

Data Availability Statement

The original contributions presented in the study are included in the article.

Conflicts of Interest

The authors declare no conflict of interest.

Appendix A

Applsci 14 07902 i001
Applsci 14 07902 i002
Applsci 14 07902 i003
Applsci 14 07902 i004
Applsci 14 07902 i005

References

  1. de la Vallee Poussin, C.J. Recherches analytiques sur la theorie des nombres premiers. Ann. Soc. Sci. Bruxelles 1896, 20, 183–256. [Google Scholar]
  2. Euler, L. Variae observations circa series infinitas. Comment. Acad. Sci. Petropolitanae 1744, 9, 160–188. [Google Scholar]
  3. Hadamard, J. Sur la distribution des zeros de la function ς(s) et ces consequences aritmetiques. Bull. Société Mathématique Fr. 1896, 24, 199–220. [Google Scholar] [CrossRef]
  4. Riemann, B. Uber die Anzahl der Primzahlen unter einer gegebenen Groβe. Monatsberichte Berl. Akad. 1859, 671–680. [Google Scholar]
  5. Bateman, P.T.; Horn, R.A. A heuristic asymptotic formula concerning the distribution of prime numbers. Math. Comput. 1962, 16, 363–367. [Google Scholar] [CrossRef]
  6. Iovane, G. The distribution of prime numbers: The solution comes from dynamical processes and genetic algorithms. Chaos Solitons Fractals 2008, 37, 23–42. [Google Scholar] [CrossRef]
  7. Naser, S.M. Some characterizations of twin prime numbers and their application. Master Sci. Thesis 2021. Available online: http://lib.buet.ac.bd:8080/xmlui/handle/123456789/6036 (accessed on 27 July 2024).
  8. Iovane, G.; Amorosia, A.; Benedetto, E.; Lamponi, G. An Information Fusion approach based on prime numbers coming from RSA algorithm and Fractals for secure coding. J. Discret. Math. Sci. Cryptogr. 2015, 18, 455–479. [Google Scholar] [CrossRef]
  9. Liu, C. A Study of Relationship between RSA Public Key Cryptosystem and Goldbach’s Conjecture Properties. Int. J. Netw. Secur. 2015, 17, 445–453. [Google Scholar]
  10. Boatto, A. Key Cryptography RSA. SSRN Electron. J. 2018. [Google Scholar] [CrossRef]
  11. Connes, A. Trace formula in non-commutative geometry and the zeros of the Riemann zeta function. Sel. Math. 1999, 5, 29–106. [Google Scholar] [CrossRef]
  12. Erdos, P. The difference of consecutive primes. Duke Math. J. 1940, 6, 438–441. [Google Scholar] [CrossRef]
  13. Goldstein, G.L. A history of the prime number theorem. Am. Math. Mon. 1973, 80, 599–615. [Google Scholar] [CrossRef]
  14. Wong, B. On the twin primes. Bull. Pure Appl. Sci. Section E Math. Stat. 2021, 40, 149–154. [Google Scholar] [CrossRef]
  15. Benedetto, E.; Iovane, G. Heuristically Sifting Twins. Resonance 2023, 28, 1505–1512. [Google Scholar] [CrossRef]
  16. Bombieri, E.; Davenport, H. Small differences between prime numbers. Proc. R. Soc. London. Ser. Math. Phys. Sci. 1966, 293, 1–18. [Google Scholar] [CrossRef]
  17. Goldston, D.A. On Bombieri and Davenport’s theorem concerning small gaps between primes. Mathematika 1992, 39, 10–17. [Google Scholar] [CrossRef]
  18. Hardy, G.H.; Littlewood, J.E. Some problems of ‘Partitio Numerorum’ III: On the expression of a number as a sum of primes. Acta Math. 1923, 44, 1–70. [Google Scholar] [CrossRef]
  19. Rankin, R.A. The difference between consecutive prime numbers. II. Proc. Camb. Philos. Soc. 1938, 36, 255–266. [Google Scholar] [CrossRef]
  20. Brun, V. La série 1/5 + 1/7 + 1/11 + 1/13 + 1/17 + 1/19 + 1/29 + 1/31 + 1/41 + 1/43 + 1/59 + 1/61 + …, où les dénominateurs sont ‘nombres premieres jumeaux’ est convergente ou finie. Bull. Sci. Mathématiques 1919, 43, 124–128. [Google Scholar]
  21. Abd-Elnaby, M.; El-Baz, D. Development of the Sieve of Eratosthenes and Proof of the Sieve of Sundaram. arXiv 2021, arXiv:2102.06653. [Google Scholar]
  22. Das, A.; Madhavan, C.E.V. Performance Comparison of Linear Sieve and Cubic Sieve Algorithms for Discrete Logarithms over Prime Fields. In Lecture Notes in Computer Science, Proceedings of the Algorithms and Computation: 10th International Symposium, ISAAC’99 Chennai, India, 16–18 December 1999 Proceedings 10; Springer: Berlin/Heidelberg, Germany, 1999. [Google Scholar]
  23. Atkin, A.O.L.; Bernstein, D.J. Prime sieves using binary quadratic forms. Math. Comput. 2004, 73, 1023–1030. [Google Scholar] [CrossRef]
  24. Hartman, S.; Sorenson, J.P. Reducing the Space Used by the Sieve of Eratosthenes When Factoring. arXiv 2024, arXiv:2406.09150. [Google Scholar]
  25. Agrawal, M.; Kayal, N.; Saxena, N. PRIMES is in P. Ann. Math. 2004, 160, 781–793. [Google Scholar] [CrossRef]
Figure 1. Comparison of algorithms for calculating k—the graph illustrates the relationship between the value of k and the fraction.
Figure 1. Comparison of algorithms for calculating k—the graph illustrates the relationship between the value of k and the fraction.
Applsci 14 07902 g001
Figure 2. Efficiency gain of the smart algorithm.
Figure 2. Efficiency gain of the smart algorithm.
Applsci 14 07902 g002
Figure 3. Relationship time—prime numbers generated and the number of prime numbers generated. The curve illustrates how the number of primes generated increases over time, eventually reaching a plateau as time progresses.
Figure 3. Relationship time—prime numbers generated and the number of prime numbers generated. The curve illustrates how the number of primes generated increases over time, eventually reaching a plateau as time progresses.
Applsci 14 07902 g003
Figure 4. Polynomial regression of degree 15 on prime number generation—the graph illustrates the results of applying a polynomial regression of degree 15 to model the relationship between the time elapsed (in seconds) and the number of primes generated.
Figure 4. Polynomial regression of degree 15 on prime number generation—the graph illustrates the results of applying a polynomial regression of degree 15 to model the relationship between the time elapsed (in seconds) and the number of primes generated.
Applsci 14 07902 g004
Table 1. Sequences of 2k − 1, 2k + 1 with k   Ν .
Table 1. Sequences of 2k − 1, 2k + 1 with k   Ν .
k 2 k 1 2 k + 1
113
235
357
479
5911
61113
71315
81517
91719
101921
112123
122325
132527
142729
152931
163133
173335
183537
193739
Table 2. Comparison of classical and smart algorithms across different values of k ~   —the table presents a side-by-side comparison of the computational load required by the classical algorithm versus the smart algorithm for various values of k ~   ranging from 1 to 1010.
Table 2. Comparison of classical and smart algorithms across different values of k ~   —the table presents a side-by-side comparison of the computational load required by the classical algorithm versus the smart algorithm for various values of k ~   ranging from 1 to 1010.
k ~ Classical AlgorithmSmart Algorithm
1 1 × 1 = 1 1
1013629
10 2 136,5673653
10 3 112,464,651333,385
10 10 1.1 × 10 26 3.3 × 10 19
Table 3. Generated twin prime pairs—the table shows a selection of the 896,062 twin prime pairs identified in the experiment, including the smallest (3, 5) and the largest (22,309,2671, 22,309,2673). The dataset highlights the algorithm’s efficiency in identifying twin primes across a wide numeric range. Consequently, the first column is the value k, while the second and the third columns are the first and the second elements of a couple of twin prime numbers.
Table 3. Generated twin prime pairs—the table shows a selection of the 896,062 twin prime pairs identified in the experiment, including the smallest (3, 5) and the largest (22,309,2671, 22,309,2673). The dataset highlights the algorithm’s efficiency in identifying twin primes across a wide numeric range. Consequently, the first column is the value k, while the second and the third columns are the first and the second elements of a couple of twin prime numbers.
I n d e x P1P2
03 5
157
2 1113
31719
42931
54143
896,056223,091,501223,091,503
896,057223,091,549223,091,551
896,058223,091,621223,091,623
896,059223,092,047223,092,049
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Iovane, G.; Di Gironimo, P.; Benedetto, E.; D’Alfonso, V. Some Properties and Algorithms for Twin Primes. Appl. Sci. 2024, 14, 7902. https://doi.org/10.3390/app14177902

AMA Style

Iovane G, Di Gironimo P, Benedetto E, D’Alfonso V. Some Properties and Algorithms for Twin Primes. Applied Sciences. 2024; 14(17):7902. https://doi.org/10.3390/app14177902

Chicago/Turabian Style

Iovane, Gerardo, Patrizia Di Gironimo, Elmo Benedetto, and Vittorio D’Alfonso. 2024. "Some Properties and Algorithms for Twin Primes" Applied Sciences 14, no. 17: 7902. https://doi.org/10.3390/app14177902

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop