Formula for primes

From testwiki
Jump to navigation Jump to search

Template:Short description Template:Use dmy dates In number theory, a formula for primes is a formula that outputs prime numbers. Such formulas for calculating primes do exist; however, they are computationally very slow, compared to a simple algorithm for prime-finding. A number of constraints are known, showing what such a "formula" can and cannot be.

Formulas based on Wilson's theorem

A simple formula that produces all primes, albeit mostly interspersed by the prime number 2, is

f(n)=⌊n!mod(n+1)n⌋(n−1)+2

for positive integer n, where ⌊ ⌋ is the floor function, which rounds down to the nearest integer. The first few values of the function are 2, 2, 3, 2, 5, 2, 7, 2, 2, 2, 11...[1]

The formula works because by Wilson's theorem, n+1 is prime if and only if n!≡n(modn+1). Thus, when n+1 is prime, the first factor in the product becomes one, and the formula produces the prime number n+1. But when n+1 is not prime, the first factor becomes zero and the formula produces the prime number 2.Template:Sfn This formula is not an efficient way to generate prime numbers because evaluating n!mod(n+1) requires about n−1 multiplications and reductions modulo n+1.

In 1964, Willans gave the formula

pn=1+∑i=12n⌊(n∑j=1i⌊(cos⁡(j−1)!+1jπ)2⌋)1/n⌋

for the nth prime number pn.Template:Sfn This formula reduces to Template:SfnTemplate:Sfn

pn=1+∑i=12n[π(i)<n];

that is, it tautologically defines pn as the smallest integer m for which the prime-counting function π(m) is at least n. This formula is also not efficient. In addition to the appearance of (j−1)!, it computes pn by adding up pn copies of 1; for example,

p5=1+1+1+1+1+1+1+1+1+1+1+0+0+…+0=11.

The articles What is an Answer? by Herbert Wilf (1982)Template:Sfn and Formulas for Primes by Underwood Dudley (1983)Template:Sfn 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 mod as a function:Template:Sfn

pn=∑i=0n2(1−˙((∑j=0i(j−˙1)!2modj)−˙n)).

Here, −˙ is the monus operator, defined as a−˙b=max⁡(a−b,0), and xmod0 is defined to be x.

Recurrence relations for primes

Gandhi's formula

In 1971, J. M. Gandhi proved that pn=⌊1−log2(sn−1−12)⌋,where sn=∑d|pn#μ(d)2d−1, μ is the Möbius function and d runs through all divisors of pn#, the primorial of pn.[2][3][4] This formula should be seen as a recurrence relation for the prime numbers, expressing pn in terms of p1,p2,…,pn−1.

This expression for sn given by Gandhi results from an application of a modified Sieve of Eratosthenes operating on the exponents of the powers of 12 in the sum ∑k=1∞12k after n steps. More precisely, Gandhi showed that sn=121+12pn+1+…, where the dots represent terms with increasing exponents greater than pn+1.[4] There are analog recurrences where the process is done in a base b other than 2.[5][6]

In 2025, a simpler expression for sn was published:

sn={12pn#−1∏i=1n2pn#−2pn#/pi2pn#/pi−1}, where {x} denotes the fractional part of x.[7]

It is based on a more clever use of the Sieve of Eratosthenes through the Chinese remainder theorem.

Golomb's formula

Inspired by Gandhi's proof, Golomb proved the following recurrence[5]pn=lims→∞(ζ(s)∏k=1n−1(1−pk−s)−1)−1s,where ζ denotes the Riemann zeta function. It is based on the Euler product for ζ.

Prime-representing constants

The notion of continued fraction can be used to define the constant u1=[p1,p2,p3,...]=2.31303673643... Template:OEIS from which we can recover the prime number sequence using the following recurrence relationship un+1=(un−⌊un⌋)−1, and it follows that pn=⌊un⌋.

An alternative construction was given by Fridman et al.Template:Sfn. Given the constant f1=2.920050977316… Template:OEIS, for n≥2, define the sequence fn=⌊fn−1⌋(fn−1−⌊fn−1⌋+1) where ⌊ ⌋ is the floor function. Then for n≥1, pn=⌊fn⌋. The initial constant f1=2.920050977316 given in the article is precise enough for equation (Template:EquationNote) to generate the primes through 37, the twelfth prime.

The exact value of f1 that generates all primes is given by the rapidly-converging series

f1=∑n=1∞pn−1pn−1#=2−11+3−12+5−12⋅3+7−12⋅3⋅5+⋯,

The more digits of f1 that we know, the more primes equation (Template:EquationNote) 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:

f1≃2.920050977316134712092562917112019.

This has enough digits for equation (Template:EquationNote) to yield again the 25 primes less than 100.

Mills' formula

The first such formula known was established by Template:Harvs, who proved that there exists a real number A such that, if

dn=A3n

then

⌊dn⌋=⌊A3n⌋

is a prime number for all positive integers n.Template:Sfn If the Riemann hypothesis is true, then the smallest such A has a value of around 1.3063778838630806904686144926... Template:OEIS and is known as Mills' constant.Template:Sfn This value gives rise to the primes ⌊d1⌋=2, ⌊d2⌋=11, ⌊d3⌋=1361, ... Template:OEIS. Very little is known about the constant A. 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 the floor function in the formula. Tóth proved that there also exists a constant B such that

⌈Brn⌉

is also prime-representing for r>2.106….Template:Sfn

In the case r=3, the value of the constant B begins with 1.24055470525201424067... The first few primes generated are:

2,7,337,38272739,56062005704198360319209,
176199995814327287356671209104585864397055039072110696028654438846269,…

Without assuming the Riemann hypothesis, Elsholtz developed several prime-representing functions similar to those of Mills. For example, if A=1.00536773279814724017…, then ⌊A1010n⌋ is prime for all positive integers n. Similarly, if A=3.8249998073439146171615551375…, then ⌊A313n⌋ is prime for all positive integers n.Template:Sfn

Wright's formula

A tetrationally growing prime-generating formula similar to Mills' comes from a theorem of E. M. Wright. He proved that there exists a real number α such that, if

g0=α and
gn+1=2gn for n≥0,

then

⌊gn⌋=⌊2…22α⌋

is prime for all n≥1.Template:Sfn Wright gives the first seven decimal places of such a constant: α=1.9287800. This value gives rise to the primes ⌊g1⌋=⌊2α⌋=3, ⌊g2⌋=13, and ⌊g3⌋=16381. ⌊g4⌋ is even, and so is not prime. However, with α=1.9287800+8.2843⋅10−4933, ⌊g1⌋, ⌊g2⌋, and ⌊g3⌋ are unchanged, while ⌊g4⌋ is a prime with 4932 digits.Template:Sfn This sequence of primes cannot be extended beyond ⌊g4⌋ without knowing more digits of α. Like Mills' formula, and for the same reasons, Wright's formula cannot be used to find primes.

Plouffe's formulas

In 2018 Simon Plouffe conjectured a set of formulas for primes. Similarly to the formula of Mills, they are of the form

{a0rn}

where { } is the function rounding to the nearest integer. For example, with a0≈43.80468771580293481 and r=5/4, this gives 113, 367, 1607, 10177, 102217... Template:OEIS. Using a0=10500+961+ε and r=1.01 with ε a certain number between 0 and one half, Plouffe found that he could generate a sequence of 50 probable 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.Template:SfnTemplate:Refn

Prime formulas and polynomial functions

It is known that no non-constant polynomial function P(n) with integer coefficients exists that evaluates to a prime number for all integers n. The proof is as follows: suppose that such a polynomial existed. Then P(1) would evaluate to a prime p, so P(1)≡0(modp). But for any integer k, P(1+kp)≡0(modp) also, so P(1+kp) cannot also be prime (as it would be divisible by p) unless it were p itself. But the only way P(1+kp)=P(1)=p for all k is if the polynomial function is constant. The same reasoning shows an even stronger result: no non-constant polynomial function P(n) exists that evaluates to a prime number for almost all integers n.

Euler first noticed (in 1772) that the quadratic polynomial

P(n)=n2+n+41

is prime for the 40 integers n=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… For n=40, it produces a square number, 1681, which is equal to 41×41, the smallest composite number for this formula for n≥0. If 41 divides n, it divides P(n) too. Furthermore, since P(n) can be written as n(n+1)+41, if 41 divides n+1 instead, it also divides P(n). The phenomenon is related to the Ulam spiral, which is also implicitly quadratic, and the class number; this polynomial is related to the Heegner number 163=4⋅41−1. There are analogous polynomials for p=2,3,5,11 and 17 (the lucky numbers of Euler), corresponding to other Heegner numbers.

Given a positive integer S, there may be infinitely many c such that the expression n2+n+c is always coprime to S. The integer c may be negative, in which case there is a delay before primes are produced.

Similarly, other polynomials (of higher degree) produces finite sequences of prime numbers.[8] In 2010, Dress and Landreau found the following polynomial representing a record-breaking 58 primes at consecutive values:[9][10]Q(n)=172n6−524n5−149372n4+10278n3+10047118n2−119716n−57347More precisely, |Q(n)| is prime for n ranging from -42 to 15.

It is known, based on Dirichlet's theorem on arithmetic progressions, that linear polynomial functions L(n)=an+b produce infinitely many primes as long as a and b are relatively prime (though no such function will assume prime values for all values of n). Moreover, the Green–Tao theorem says that for any k there exists a pair of a and b, with the property that L(n)=an+b is prime for any n from 0 through k−1. However, Template:As of the best known result of such type is for k=27:

224584605939537911+18135696597948930n

is prime for all n from 0 through 26.Template:Refn It is not even known whether there exists a univariate polynomial of degree at least 2, that assumes an infinite number of values that are prime; see Bunyakovsky conjecture.

Rowland's prime-generating sequence

Another prime generator is defined by the recurrence relation

an=an−1+gcd⁡(n,an−1),a1=7,

where gcd denotes the greatest common divisor function. The sequence of differences an+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, ... Template:OEIS. Template:Harvtxt 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 always odd 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.Template:Sfn

This recurrence is rather inefficient. In perspective, it is trivial to write an algorithm to generate all prime numbers (from the definition), and many more efficient algorithms are known. Thus, such recurrence relations are more a matter of curiosity than of practical use.

Prime-describing system of Diophantine equations

Because the set of primes is a computably enumerable set, by Matiyasevich's theorem, it can be obtained from a system of Diophantine equations. Template:Harvtxt found an explicit set of 14 Diophantine equations in 26 variables a,b,...,z, such that a given number k+2 is prime if and only if that system has a solution in nonnegative integers:Template:Sfn

α0=wz+h+j−q=0α1=(gk+2g+k+1)(h+j)+h−z=0α2=16(k+1)3(k+2)(n+1)2+1−f2=0α3=2n+p+q+z−e=0α4=e3(e+2)(a+1)2+1−o2=0α5=(a2−1)y2+1−x2=0α6=16r2y4(a2−1)+1−u2=0α7=n+ℓ+v−y=0α8=(a2−1)ℓ2+1−m2=0α9=ai+k+1−ℓ−i=0α10=((a+u2(u2−a))2−1)(n+4dy)2+1−(x+cu)2=0α11=p+ℓ(a−n−1)+b(2an+2a−n2−2n−2)−m=0α12=q+y(a−p−1)+s(2ap+2a−p2−2p−2)−x=0α13=z+pℓ(a−p)+t(2ap−p2−1)−pm=0

The 14 equations α0,…,α13 can be used to produce a prime-generating polynomial inequality in 26 variables:

(k+2)(1−α02−α12−⋯−α132)>0

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 variables a,b,...,z range over the nonnegative integers.

A general theorem of Matiyasevich 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.Template:Sfn 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.Template:Sfn

See also

Notes

Template:Reflist

References

Template:Div col

Template:Div col end

Further reading

Template:Prime number classes

  1. ↑ Template:Cite OEIS
  2. ↑ J. M. Gandhi, Formulae for the nth prime, Proceedings of the Washington State University Conference on Number Theory 96–107, Washington State University, Pullman, WA, 1971.
  3. ↑ Template:Cite journal
  4. ↑ 4.0 4.1 Template:Cite journal
  5. ↑ 5.0 5.1 Template:Cite journal
  6. ↑ Template:Cite journal
  7. ↑ Template:Cite journal
  8. ↑ Template:Cite arXiv
  9. ↑ Template:Cite web.
  10. ↑ Template:Cite arXiv