Innumber theory, aformula for primes is aformula generating theprime numbers, exactly and without exception. Formulas for calculating primes do exist; however, they are computationally very slow. A number of constraints are known, showing what such a "formula" can and cannot be.
for positiveinteger, where is thefloor function, which rounds down to the nearest integer.ByWilson's theorem, is prime if and only if. Thus, when is prime, the first factor in the product becomes one, and the formula produces the prime number. But when is not prime, the first factor becomes zero and the formula produces the prime number 2.[1]This formula is not an efficient way to generate prime numbers because evaluating requires about multiplications and reductions modulo.
In 1964, Willans gave the formula
for theth prime number.[2]This formula reduces to[3][4]
that is, it tautologically defines as the smallest integer for which theprime-counting function is at least. This formula is also not efficient. In addition to the appearance of, it computes by adding up copies of; for example,
The articlesWhat is an Answer? byHerbert Wilf (1982)[5] andFormulas for Primes byUnderwood Dudley (1983)[6] have further discussion about the worthlessness of such formulas.
A shorter formula based on Wilson's theorem was given by J. P. Jones in 1975, using as a function:[7]
The 14 equations can be used to produce a prime-generating polynomial inequality in 26 variables:
That is,
is a polynomial inequality in 26 variables, and the set of prime numbers is identical to the set of positive values taken on by the left-hand side as the variablesa,b, ...,z range over the nonnegative integers.
A general theorem ofMatiyasevich says that if a set is defined by a system of Diophantine equations, it can also be defined by a system of Diophantine equations in only 9 variables.[9] Hence, there is a prime-generating polynomial inequality as above with only 10 variables. However, its degree is large (in the order of 1045). On the other hand, there also exists such a set of equations of degree only 4, but in 58 variables.[10]
The first such formula known was established by W. H. Mills (1947), who proved that there exists areal numberA such that, if
then
is a prime number for all positive integers.[11] If theRiemann hypothesis is true, then the smallest such has a value of around 1.3063778838630806904686144926... (sequenceA051021 in theOEIS) and is known asMills' constant.[12] This value gives rise to the primes,,, ... (sequenceA051254 in theOEIS). Very little is known about the constant (not even whether it isrational). This formula has no practical value, because there is no known way of calculating the constant without finding primes in the first place.
There is nothing special about thefloor function in the formula. Tóth proved that there also exists a constant such that
In the case, the value of the constant begins with 1.24055470525201424067... The first few primes generated are:
Without assuming the Riemann hypothesis, Elsholtz developed several prime-representingfunctions similar to those of Mills. For example, if, then is prime for all positive integers. Similarly, if, then is prime for all positive integers.[14]
Atetrationally growing prime-generating formula similar to Mills' comes from a theorem ofE. M. Wright. He proved that there exists a real numberα such that, if
and
for,
then
is prime for all.[15]Wright gives the first seven decimal places of such a constant:. This value gives rise to the primes,, and. iseven, and so is not prime. However, with,,, and are unchanged, while is a prime with 4932 digits.[16] Thissequence of primes cannot be extended beyond without knowing more digits of. Like Mills' formula, and for the same reasons, Wright's formula cannot be used to find primes.
Given the constant (sequenceA249270 in theOEIS), for, define the sequence
1
where is thefloor function.Then for, equals theth prime:,,, etc.[17]The initial constant given in the article is precise enough for equation (1) to generate the primes through 37, theth prime.
Theexact value of that generatesall primes is given by the rapidly-convergingseries
where is theth prime, and is the product of all primes less than. The more digits of that we know, the more primes equation (1) will generate. For example, we can use 25 terms in the series, using the 25 primes less than 100, to calculate the following more precise approximation:
This has enough digits for equation (1) to yield again the 25 primes less than 100.
As with Mills' formula and Wright's formula above, in order to generate a longer list of primes, we need to start by knowing more digits of the initial constant,, which in this case requires a longer list of primes in its calculation.
In 2018Simon Plouffeconjectured a set of formulas for primes. Similarly to the formula of Mills, they are of the form
where is the function rounding to the nearest integer. For example, with and, this gives 113, 367, 1607, 10177, 102217... (sequenceA323176 in theOEIS). Using and with a certain number between 0 and one half, Plouffe found that he could generate a sequence of 50probable primes (with high probability of being prime). Presumably there exists an ε such that this formula will give an infinite sequence of actual prime numbers. The number of digits starts at 501 and increases by about 1% each time.[18][19]
It is known that no non-constant polynomial functionP(n) with integer coefficients exists that evaluates to a prime number for all integersn. The proof is as follows: suppose that such a polynomial existed. ThenP(1) would evaluate to a primep, so. But for any integerk, also, so cannot also be prime (as it would be divisible byp) unless it werep itself. But the only way for allk is if the polynomial function is constant.The same reasoning shows an even stronger result: no non-constant polynomial functionP(n) exists that evaluates to a prime number foralmost all integersn.
is prime for the 40 integersn = 0, 1, 2, ..., 39, with corresponding primes 41, 43, 47, 53, 61, 71, ..., 1601. The differences between the terms are 2, 4, 6, 8, 10... Forn = 40, it produces asquare number, 1681, which is equal to 41 × 41, the smallestcomposite number for this formula forn ≥ 0. If 41 dividesn, it dividesP(n) too. Furthermore, sinceP(n) can be written asn(n + 1) + 41, if 41 dividesn + 1 instead, it also dividesP(n). The phenomenon is related to theUlam spiral, which is also implicitly quadratic, and theclass number; this polynomial is related to theHeegner number. There are analogous polynomials for (thelucky numbers of Euler), corresponding to other Heegner numbers.
Given a positive integerS, there may be infinitely manyc such that the expressionn2 +n +c is always coprime toS. The integerc may be negative, in which case there is a delay before primes are produced.
It is known, based onDirichlet's theorem on arithmetic progressions, that linear polynomial functions produce infinitely many primes as long asa andb arerelatively prime (though no such function will assume prime values for all values ofn). Moreover, theGreen–Tao theorem says that for anyk there exists a pair ofa andb, with the property that is prime for anyn from 0 throughk − 1. However, as of 2020,[update] the best known result of such type is fork = 27:
is prime for alln from 0 through 26.[20] It is not even known whether there exists aunivariate polynomial of degree at least 2, that assumes an infinite number of values that are prime; seeBunyakovsky conjecture.
where gcd(x,y) denotes thegreatest common divisor ofx andy. The sequence of differencesan+1 −an starts with 1, 1, 1, 5, 3, 1, 1, 1, 1, 11, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 23, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 47, 3, 1, 5, 3, ... (sequenceA132199 in theOEIS).Rowland (2008) proved that this sequence contains only ones and prime numbers. However, it does not contain all the prime numbers, since the terms gcd(n + 1,an) are alwaysodd and so never equal to 2. The same paper conjectures that the sequence contains all odd primes: in fact, 587 is the smallest odd prime not appearing in the first 10,000 outcomes different from 1.[21]
This recurrence is rather inefficient. In perspective, it is trivial to write an algorithm to generate all prime numbers (from the definition), and manymore efficient algorithms are known. Thus, such recurrence relations are more a matter of curiosity than of practical use.
^Simon Plouffe (2019), "A set of formulas for primes",arXiv:1901.01849 [math.NT] As of January 2019, the number he gives in the appendix for the 50th number generated is actually the 48th.
Regimbal, Stephen (1975), "An explicit Formula for the k-th prime number",Mathematics Magazine,48 (4), Mathematical Association of America:230–232,doi:10.2307/2690354,JSTOR2690354.
A Venugopalan.Formula for primes, twinprimes, number of primes and number of twinprimes. Proceedings of the Indian Academy of Sciences—Mathematical Sciences, Vol. 92, No 1, September 1983,pp. 49–52errata