The Linear and Quadratic Nature of Sequences for Determining Prime Numbers by Elimination of Composites

Corresponding author: Jonathan M. Dugas Department of Electrical Engineering, Tennessee Technological University, Cookeville, USA Email: jmdugas@charter.net Abstract: A previously derived set of sequences for generating prime numbers is modified by various algebraic and trigonometric manipulations. The modified sequences are then used to more efficiently generate prime numbers. The modified sequences are simplified from their original form and are much easier to implement into a computer program. It is shown by computation that the modified sequences more efficiently determine prime numbers because the modified sequences provide flexibility with their implementation. The added flexibility allows for the removal of redundancy in the overall process, which decreases the amount of data to process; thus, the efficiency of the prime number generator is significantly improved.


Introduction
In "Sequences for Determination of Prime Numbers by Elimination of Composites," it was proven that there exists a function, simply termed the (a) function, that will generate all prime numbers starting with 5 up to some number (N), and the function generates composites periodically (Dugas and O'Connor, 2017). The (a) function is as shown in Equation 1: It was also shown that the (a) function can be written as shown in Equation 2: There are many alternative ways to represent such an equation. For example and as shown in Equation 3, the squares of sine and cosine can be used in place of the absolute values of sine and cosine, respectively: Using the half angle formulas for the sine squared and cosine squared terms, Equation 4 is obtained: In this study, the (a) function will be modified such that the summation operator is removed. The summation operators for the (i (not prime) ) equation, which is the equation used to determine the composites generated by the (a) function, are removed as well. By removing these summation operators, computer resources will be preserved because more flexibility is established in choosing which values of (i (not prime) ) need to be calculated and which values can be ignored. The following equation was used in "Sequences for Determination of Prime Numbers by Elimination of Composites" to determine the indices of (i) that correspond to composites generated by the (a) function (Dugas and O'Connor, 2017) The derivation of Equation 6 will not be explained; however, it will be shown that the components comprising Equation 6 can be alternatively represented by linear and quadratic equations, which significantly simplifies its form (Dugas and O'Connor, 2017). The modified (a) function and the simplified form of Equation 6 will then be used to generate prime numbers. From a computer science point of view, the efficiency of the overall prime number generator can be improved by simplifying the (a) function and Equation 6. The primary reason the efficiency will be improved is the removal of the summation operators from the (a) function and Equation 6. By removing the summation operators from Equation 6, it becomes possible to determine which of its values need to be calculated and which are redundant and can be negated. It becomes possible to negate redundancy in Equation 6 by the removal of the summation operators because the current values are no longer dependent on any previous values of Equation 6. The same is true for the (a) function. If it is determined that an index of the (a) function will generate a composite number, that index can be omitted because the (a) function is no longer dependent on any of its previous values. The purpose of this work is to present a modified form of the (a) function and Equation 6, report on the linear and quadratic nature of Equation 6, and present a set of equations that could potentially be used to more efficiently generate prime numbers. The validity of the method will be proven by computation using computer software to determine all prime numbers between one and one billion.

Experimental Procedure
Equation 7 is a mathematical representation of the algorithm used to calculate all prime numbers between one and one billion, using the C++ programming language. The algorithm in Equation 7 is a significantly simplified version of the prime number algorithm used in previous experiments (Dugas and O'Connor, 2017). The derivation and specifics of Equation 7 will be explained in detail in the Discussion section. However, it is worth noting that Equation 7 is a more efficient prime number generator because there are no summation operators: The prime number generators used in previous experiments possessed a total of four summation operators (Dugas and O'Connor, 2017). By removing the summation operators, the number of calculations the program performs can be reduced because more flexibility in deciding which values of (i (not prime) ) are needed and which values can be negated is established. Equation 7 shows that (n) does not need to equal any values generated by the equation for (D) or any value of (i (not prime) ) for (1≤n≤7) and all (m), which eliminates a significant portion of the redundancy in (i (not prime) ). The specifics of why (n) will generate redundancy for those values of (D) and (i (not prime) ) will also be explained in the Discussion section.
The flow diagram in Fig. 1 shows the logic used to calculate the values of the (a) function and (i (not prime) ) and determine prime numbers (Gaddis and Krupnpw, 2007). The values of the (i (not prime) ) equation were calculated first for all (n) and (m), such that (1≤i (not prime) ≤N). A nested For loop was used to calculate all values of (i (not prime) ), as shown in Fig. 1. The outer For loop pertains to the (n) variable and the inner For loop pertains to the (m) variable. If (n) equaled any value of (i (not prime) ) for (1≤n≤7) and all (m), that value of (n) was negated and the inner loop pertaining to (m) was also negated. It should be noted that (m) is chosen such that (i (not prime) ) never exceeds (N), as indicated in Equation 7 where the limits on (i (not prime) ) are (1≤ i (not prime) ≤N) (Gaddis and Krupnpw, 2007).
Once all needed values of (i (not prime) ) were calculated, they were arranged into 17 different segments, which were arranged in sequential order. Each segment was stored in one of 17 different text files. The next step was to begin calculating the values of the (a) function for all values of (n) not equal to any value of (i (not prime) ). The values of (i (not prime) ) were read from the text files in which they were stored and if (n) was not equal to any of the values of (i (not prime) ), the value of the (a) function was calculated and output to the prime number text file. The text file was to contain all primes between one and one billion after the program executed.

Results
After the described program executed, there were 50,847,534 integers in the prime number text file. There are exactly that many prime numbers between one and one billion. The last prime number in the text file was 999,999,937, which is the last prime number between one and one billion. Table 1 contains the density of primes for all primes in the text file for (3N) approximately equal to powers of ten up to one billion.  The results are in good agreement with the known density of primes data for powers of ten between one and one billion and the prime number theorem, which states that the density of prime numbers should decrease as (N) approaches infinity (Crandall and Pomerance, 2006). All integers in the prime number text file were in fact prime numbers, the density of primes decreased for larger values of (N) and the experiment successfully validated the reasoning used to simplify the prime number generator.

Discussion
The Linear Nature of the (a) Function To modify the (a) function such that the summation operator is removed, begin with Equation 8 (Mandal and Asif, 2007): Equation 8 The only difference in Equation 5 and 9 is that the cosine term in Equation 5 has been replaced with a (-1) raised to an appropriate exponent (Dugas and O'Connor, 2017). Equation 9 can be modified to obtain the two sums in Equation 10: It can be directly shown that Equation 10 reduces to the two lines in Equation 11: for n odd a n n for n even n N If a single equation for the (a) function is desired, the (a) function can be written as shown in Equation 12: 3 2 sin 3 1 cos 2 2 1 n n a n n n n N Using the trigonometric identity in Equation (13) The approach just used to simplify the (a) function is also used on more than one occasion to simplify (i (not prime) ). Simplifying the (a) function and (i (not prime) ) in this way allows for the summation operators in both equations to be eliminated, improving the overall efficiency of the prime number generator.
The Linear and Quadratic Nature of (i (not prime) ) To determine the indices of the composites generated by the (a) function so that the composites can be eliminated, Equation 6 or some form of Equation 6 should be used. Observe Fig. 2. The (D) component of Equation 6, which stands for the diagonal of (i (not prime) ) when its values are inserted into a matrix of (k) rows and (j) columns, is shown in Equation 15, and the graph of (D) with respect to the indices of (k) is shown in Fig. 2 (Dugas and O'Connor, 2017): As shown in Fig. 2, (D) can be alternatively represented by two quadratic equations. The solid line, which has the appearance of a saw tooth plot, is a graph of all values generated by (D) for (1≤n≤7). Figure 2 shows that (D) is comprised of two parabolas and both parabolas are plotted using dashed lines. The top parabola with respect to the saw-tooth line is utilized for odd values of (k) and the parabola on the bottom is utilized for even values of (k).
If (n) is odd, it can be directly shown that Likewise if (n) is even, it can be directly shown that: Equation 21 summarizes the two quadratics and there is a parabola for the odd values of (n) and a parabola for the even values of (n): (D) can then be simplified as shown in Equation (24) (Mandal and Asif, 2007).
(D) has now been written into quadratic components and simplified and the linear components of (i (not prime) ) can be similarly derived. Observe Fig. 3. As (j) is iterated for (k = 1), (i (not prime) ), shown as a solid, blue, saw-tooth line, alternates between two lines that are shown as a pair of dashed, blue lines. There is a dashed line for the odd values of (j) and a dashed line for the even values of (j) and that is true for any given value of (k). As another example and for (k = 2), (i (not prime) ) is shown as a solid, green, saw-tooth line alternating between two dashed, It can be directly shown that Equation 28 The u(n-2) term in Equation 30 thru 31 can now be eliminated because if (n = 1), an odd value, (p) equals 7 (Zill and Cullen, 2008 Using the trigonometric identity in Equation 13 Equation 35 can be simplified further by using the trigonometric identity in Equation 13 once more, which yields Equation 36 (Mandal and Asif, 2007): Equation 37, which is termed P(n, m), is a simplified version of the prime number generator presented in previous research and it can be more efficiently implemented from a computer science point of view:  Fig. 3: Plot of (i (not prime) ) with respect to (j) for different values of (k) In P(n, m), the summations in (a), (D) and (p) have been removed by the previous simplifications. Those three components are no longer dependent on any previous values of (n); they are only dependent on the current value of (n). Simplifying (i (not prime) ) in this way allows for more flexibility in choosing which values of (n) are needed and which values of (n) cause (i (not prime) ) to generate redundant values. In other words, (n) does not need to be equal to any of the values generated by (i (not prime) ) because all of those values will be redundant. (Note that the limits of (j) and (m) are now modified such that (j) is never less than (n+1) and (m) is never less than 1. Setting the limits of (j) and (m) in this way better clarifies the range of values needed for (j) and (m)).
Observe Table 2, which is a matrix containing the values of (i (not prime) ) for (n) rows and (m) columns. Everything below the blue diagonal in red is redundant and the values on and above the diagonal are the only values needed, which is how the diagonal, (D), was derived in previous research (Dugas and O'Connor, 2017). However, some values on and above the diagonal are redundant as well. A large portion of the remaining redundancy occurs whenever (n) equals any values generated by (i (not prime) ), which is indicated by the red rows on and above the blue diagonal in Table 2. If Table  2 is extended for higher values of (m), the value of 208 in row 8 and the values of 408 and 431 in row 11 will also occur in row 1.
The remaining redundancy is slightly more complicated to identify and eliminate. Table 3 is an extension of Table 2 for higher values of (m) to provide more clarity. For (n) greater than one, (i (not prime) ) equates to a redundant value if (m) equals any value of (i (not prime) ) when (n) in (i (not prime) ) is equal to one. Likewise for (n) greater than two, (i (not prime) ) generates redundancy if (m) equals (i (not prime) ) when (n) in (i (not prime) ) is equal to two (Dugas and O'Connor, 2017).
For example, the value of 128 in column 18 also occurs in row 1. As another example, the value of 179 in column 16 also occurs in row 2. Now, a process for determining the remaining redundancy generated by the (i (not prime) ) equation has been identified, however, the last summation operator needs to be eliminated so that the current values of (i (not prime) ) are never dependent on any previous values of (i (not prime) ). The derivation used to eliminate the final summation operator from (i (not prime) ) will not be explained, but using an approach that is similar to those used to simplify a(n), (D) and (p), Equation (38) can be obtained for (i (not prime) ):  Equation 38 is a significantly simplified form of (i (not prime) ), it is much easier to use and it can be implemented much more efficiently into a computer program. Without the summation operators in (i (not prime) ), all of the values of (n) and (m) that cause (i (not prime) ) to generate redundancy can be negated, which will make the entire process more efficient. At this point, it is prudent to recognize a mathematical connection between the lines plotted in Fig. 3 and the (a) function, which provides a simpler alternative way to obtain Equation 38. Refer to Fig. 3.
The lines plotted in Fig. 3 have slopes dependent on the values of a(n) and intercepts dependent on the values of (n).
Equation 42 possesses a form of (i (not prime) ), which can be implemented without excessively generating redundant values. The current values of (i (not prime) ) no longer depend on any previous values of (i (not prime) ), which enables all redundant values to be avoided, making the entire process more efficient.

Conclusion
The results presented in this study further validate the notion that there exists an equation (the (a) function) that will generate all of the prime numbers, starting with 5, but it also generates composites periodically that are not divisible by 2 or 3. Thus, there also exists an equation for eliminating the composites. Through algebraic and trigonometric manipulations, both equations can be significantly simplified making the entire process more efficient. The process becomes more efficient because redundancy in the (i (not prime) ) equation becomes more avoidable, since more flexibility is established in choosing which values of the (i (not prime) ) need to be calculated and which values are redundant. The procedures presented in this work, outline the general process for identifying and avoiding the remaining redundancy in (i (not prime) ), but more experimentation with multiple, more elaborate computer systems is needed to generate higher order prime numbers and further validate the whole process.