In this paper, we will obtain the following integral:
Being p the number that we want to check if it is a prime or not. And being m whatever integer number higher than . If the result is zero (or it is so small that it can be considered to be zero) the number p is a prime. If not, the result will tell us how many permutations of two divisors, the number p has.
To obtain the integral (1), the following steps shall be taken. First, we will create a domain with all the composite numbers in the domain included.
Then, we will use the Fourier transform   to change from the original domain (time domain) to the frequency domain.
Using the Parseval’s theorem, we can check if a certain number is the above created domain or not. The use of Parseval’s theorem will lead to the above integration.
If the number p that we want to check is not in the domain, the result of the integration is zero and the number is a prime. If instead, the result is an integer, this integer will tell us how many permutations of two divisors the number p has. And in consequence, how many divisors, the number has.
As k and ω are independent variables, the sum can be taken outside the integral. You can see that implementation in below Matlab/Octave program (Figure 1).
Figure 1. Matlab program to check if a number is prime using integration.
2. Matrix of Composite Numbers
It is very easy to create a matrix with the only composite numbers in certain domain. We can make that each element of the matrix is the result of the product of two integers in certain domain. We can perform this operation one by one until having used all the integers. So, the result will be all the composite numbers in certain domain.
You can see an example in Figure 2.
And the result attached in Figure 3.
We can see that all the composite numbers between 4 and 10 are included in the matrix: 4, 6, 8, 9, 10. And as expected, the prime numbers 2, 3, 5 and 7 not. But we can see that the number 14 that is composite is not included. Why? Because it is composed by 7 × 2 and the 7 is not included in the multiplications. This means, the domain where it is valid that all the composite numbers are included (and none of the integers) finishes in 2 × 5 = 10 (being 5 the last number we are using in the multiplications). We can also see that it is a symmetric matrix that will have implications in the following chapters.
As 2 × 7 = 14, we know that the result will be reliable until 14. This means, all the composite numbers until 14 have to be included in the matrix: 4, 6, 8, 9, 10, 12 and 14. And not the primes: 2, 3, 5, 7, 11, 13. We can see again that the composite number 22 = 11 × 2 is not included in the matrix. This is because 11 has not be included in the multiplications. The reliable domain is until 7 × 2 = 14, as commented.
The nomenclature that we will use in the following chapters for the general case will be the following (see Figure 6).
This means, the reliable domain (the domain where all the composite numbers will be included in the matrix) will be up to 2 × (m + 1).
Figure 2. Matrix of the product of two integers within a certain domain.
Figure 3. Matrix of the result of the product of two integers within a certain domain.
Figure 4. Matrix of the products of 2 integers in the 2 to 7 domain.
Figure 5. Matrix of the results of the products of two 2 integers in the 2 to 7 domain.
Figure 6. Matrix of the products of two integers in the 2 to (m + 1) domain.
3. Including the Elements of the Composite Matrix in the Discrete Time Domain
Now, the next movements will be quite straight forward. The first thing we have to do, is to introduce these calculated composite numbers in the discrete time domain. We will put unitary delta functions in the positions of the x axis indicated by the matrix of composite numbers (Figure 7).
We can see that in the above graphic, each Dirac delta represent the product of two integers, that compose a composite number. This means, each Dirac delta means that the composite number has a factorization of two numbers. And the order counts. This is, 2 × 4 counts one and 4 × 2 counts another one.
If we have only one Dirac Delta, it means that it has only one multiplication (therefore it is a square of a prime number) like 4 = 2 × 2 or 9 = 3 × 3 for example. If the number of Dirac deltas is odd, the number has an integer square root. If the number is even, it has different permutations of different products, but it does not have an integer square root.
We can create a function that is the sum of all these deltas. And this function will have the information of all these composite numbers. This function in the discrete domain is defined like this:
This function f(n) has the information regarding all the composite numbers inside the domain 2 × (m + 1). But, the important information there is what it is not included. All the integers smaller than 2 × (m + 1) that are not included in this function, are prime numbers.
How do we spot them? If we want to know if the number 5 is prime or not. We have to check if there is a Dirac delta in position 5. This means, we have to
Figure 7. Representation in the time domain of the products of two integers, using Dirac delta functions.
check if the following function g(n) is inside the function f(n):
In general, if we want to check if whatever number p is prime, g(n) would be:
We could do this performing the multiplication one by one for all the points in x axis between the function f(n) and the function g(n).
As the function g(n) is zero everywhere except in the point 5 (or in general, in p), if the result of the multiplication point by point between f(n) and g(n) is zero, it means that f(n) does not have a Dirac delta in 5. So, number 5 is prime.
If the result is different, it will tell us the value of f(n) at that point. And the value of f(n) at that point is the number of deltas included. This means, the number of all the possible multiplications of two integers that compose that number.
The problem is that to perform this operation in the time domain, does not add any value. Because to know the result, we have to compare “manually” f(n) and g(n) to see if f(n) has a value different from zero in the position where g(n) has the delta.
This is the reason why we go to the next chapter.
4. The Frequency Domain
What we will do is to convert the functions f(n) an g(n) to the frequency domain. To do so, we use the Fourier transform.
We start with f(n). We know from signal theory that the Fourier transform of a shifted Dirac delta is:
So, the function f(n), in the frequency domain has the form F:
We can put above sum in the following form:
As you can see above, each line is a geometric series sum. So, using the known result of geometric series   , we can write:
For the function g, following the same process:
The Fourier transform would be:
5. Parseval’s Theorem
Now, we get to the point. In the chapter 2, we wanted to perform the following operation:
If the result is different from zero, it means that p is composite, as it means that g(n):
Has found another delta in the same position for the function f(n) defined before, that has only deltas in composite number positions.
This operation in the time domain does not have added value (as you have to perform all multiplications), but fortunately Marc-Antoine Parseval   found the following theorem.
The general Parseval’s theorem applied to discrete functions (as it is the case) says the following:
The asterisk* means the complex conjugate. In all the functions we are dealing in this paper are real in the time domain so in the left-hand side no conjugation is necessary.
For the right-hand side, yes, we have complex functions. But, as you can check all of them are exponential based. So, the conjugate is just to change the sign of the exponent. This is immediate from Euler’s formula   .
So, coming back, this means, we can perform the operation of multiplying point by point the two functions in the time domain, just making the definite integral form −π to π of the multiplication of the two functions (its Fourier Transform) in the frequency domain.
So, the integral in the frequency domain (that represents the multiplication point by point of the functions f(n) and g(n) in the time domain) according Parseval’s theorem is the following (and we will call q to its result):
So, summing up:
So, this is the integral we have been talking about from the beginning. Now, you know where it comes from. We will call q the result of above formula. If q is zero, p is prime, if q is different from zero, q has information regarding the number of factors. Let’s comment about it in the following chapters.
Before that, just for possible calculation issues, it is to be noted that as, k is independent from ω the sum can be taken outside the integral, as follows:
6. Number of Factors of p
We know that if p is composite, the number q (result from Equation (15)) is the number of possible combinations of multiplications of two integer numbers that get the value p. And yes, with this number we can get the number of factors that p has.
This is the formula:
Being nf1 the number of times the factor f1 is repeated, nf2 the number of times f2 is repeated and so on.
Putting in another way is:
So, the factors of the obtained number q + 2 (much smaller than p) tell us how many factors the number p originally has and how many of them are repeated.
Let’s see with an example. We apply Equation (15) to the number 20 and we get q = 4. So we can check:
This means, p has to have a factor that is repeated twice and one that appears only once. And we see that it is true:
The factor 2 is repeated twice and 5 once.
And the q is 4 because, there are four combinations of multiplications of two integers that get the result 20:
So, everything fits.
Let’s check, other ones:
p = 102
q = 6
This means, three factors that are not repeated, and in fact 102 = 2 × 3 × 17.
p = 36
q = 7
This means two factors repeated twice (each). In fact, 36 = 2 × 2 × 3 × 3.
You can see that the Formula (17) works.
We can use q to know how many factors a number p has if it is composite (or instead, detect it is a prime if q = 0).
One of the problems that this system has is that sometimes there are different solutions for the number of factors. For example, for q = 2, the typical answer is:
This means, two different factors not repeated. For example, 21 = 3 × 7 = 7 × 3.
But it could be:
For example, the number 8 = 2 × 4 = 4 × 2.
It has q = 2 (two combinations of factors) but 8 = 2 × 2 × 2. This means one factor three times, as seen before.
So, the number q could have some values that have different solutions regarding the number of factors.
7. Efficiency of the Numerical Integration Compared to Brute Force Checking
We will check that the sum and the integral of the Formula (14) are very inefficient computation-wise. And in fact, it is more efficient to start looking for factors (by brute-force) than applying the formula. You can see this easily with the Matlab program (Figure 8).
Figure 8. Matlab program to compare integration method versus brute force checking.
If we check with different numbers, we compare the efficiency of each method (as time taken is recorded).
For the following examples, I will use a Windows 10 OMEN by HP Laptop 17-an0xx Intel-Core i7-7700HQ 2.80 GHz 32 Gb RAM Nvidia GeForce GTX 1070 with the program Matlab R2018b.
For example, with p = 20:
With p = 103:
For p = 300:
We can see that for p = 300, it has taken 12.25 seconds to discover that has 16 permutations of two factors. Which leads to .
This means that has three factors (and two of them are repeated twice). (In fact, these are = 2 × 2 × 3 × 5 × 5).
But with brute-checking it took zero seconds to discover it was composite and even it has given the info of which is one of the factors (the factor 2).
Regarding this point a very detailed study should be done. You can check in the Matlab program that I have reduced the precision of the integral to increase efficiency. I have reduced the precision of 0.24, which can be considered high, but it is sufficient for low values of p.
You can change and play with the value here:
a = integral(fun,-pi,pi,’AbsTol’,0.24);
Also, I have considered implicitly that q is considered to be zero when q < 0.5 (using the function “round”).
8. Sum of the Exponential of the Factors of the Number p
In the chapter 2 we have put all the Dirac deltas as unitary Dirac deltas. But we can introduce more information, if instead of putting unitary Dirac deltas, we introduce the deltas multiplied by a number that represents the value of the factors you are using. This means, as an output we can get info regarding the factors of the number p (not only the quantity of factors but its sum).
We can check an example (see Figure 9). We can multiply the delta by an exponential that represents the two factors we are using. In this case, it is the exponential of the sum of the two factors. We will see that this representation gives us more information and permits to follow the calculations in a similar manner as before.
So, in this case:
Figure 9. Representation in the time domain of the products of the exponential of two integers, using delta functions.
To calculate Fourier transform:
Calculating the geometric series result for each line:
We call q2 this value that has this information regarding the factors. We will see how to use it in the next chapter.
One of the problems that this form has is that the exponentials ek and em could go high very quick. A way to avoid this, is to use a “calibration factor” c. This factor, will reduce this exponentials value not reducing the information. This factor should be of the order of p, and normally using the value works well. This we will see later. First, the calculation (similar to above but with the calibration factor c included).
Calculating the geometric series result for each line:
This factor q3 is equivalent (has the same information) as q2 but reducing the exponentials value, so it reduces the computing necessities.
We see what to do with them, in the next chapter.
9. Special Case: Discovering the Factors of Two-Factor Composite Numbers
There are two cases where with all this information, it is immediate to calculate the factors of a number. One of the cases is trivial. When q = 1, it means that p is a perfect square, so you can just make the square root to get it.
But there is another special case. When q = 2, it means that the number is composite but only by two factors (two prime factors). This case is used for example in RSA encryption  .
What you can do in this case is the following.
− First you calculate the q. And you see that is 2, that corresponds to (1 + 1)(1 + 1). This means, two different factors. So, you can apply the following.
− Then you calculate the q2 according (27). Or calculate q3 according (29).
− Calculate the following number using q2:
Or if you have calculated q3:
Being c the calibration factor you have chosen.
− And, then solve the following equation system (being a and b the unknown factors of p) and d is the known number calculated before:
You have the solution:
So, you can get, immediately the factors a and b. This, of course is tricky. As for the calculation of q2 you have used exponentials, summations and numerical integrals. So, the complete process, as commented, is at this stage is inefficient.
You can see the following examples result:
Figure 10. Matlab program to obtain two factors using integration.
Figure 11. Matlab program to obtain two factors using brute-force checking.
Number p = 21:
Number p = 77:
Number 323 is especially painful:
We can see that still the brute-force checking is better computer efficiency-wise than using the numerical integration.
10. Future Developments
A deeper study shall be done regarding the efficiency of the summations and the integrals. Finding an analytical solution for one of both would be the key.
In the calculation of q2, if use negative exponents for the real part, we could go to a summation that has zero in the infinity for the last element. This means we could simplify the Equation (but no improvement got at this stage).
It could be used the Euler-Maclaurin  equation to convert the integral to another summation (but no improvement has been found at this stage compared to the numerical integration).
Also, the possibility of making some prework in Equation (1) as the summation is independent of p, should be checked. But regretfully the later integration, element by element, cannot be avoided anyhow at this stage.
In this paper, it has been shown a way of checking if a number is prime or not, using numerical integration in the complex plane. At this stage, this way of calculation is inefficient compared to brute-force checking. Only if in the future an analytical solution for the integral or some prework is done, this efficiency could increase.
Also, it has been used the same method to calculate the factors for the special case where a number is composed by only two factors. Regretfully, again, the procedure is more inefficient than a brute-force checking at this stage. But it opens a new field of calculation.
A deeper study shall be done regarding the efficiency of the summations and the integrals. Finding an analytical solution for one of both would be the key. Some improvements as trying to make the sum to infinity or converting it in an integral via Euler-Maclaurin equation have been discussed. Also, the probability of making some prework in the integral or in the sum before applying to the specific number to be checked shall be studied.
Bilbao, 19th January 2019 (JAMP-v2).
To my family and friends.
 des Chênes, P. (1799) Marc-Antoine Mémoire sur les séries et sur l’intégration complète d’une équation aux différences partielles linéaire du second ordre, à coefficients constants. Sciences, mathématiques et physiques (Savants étrangers), 1, 638-648.