Misplaced Pages

Formula for primes: Difference between revisions

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
Browse history interactively← Previous editContent deleted Content addedVisualWikitext
Revision as of 16:15, 7 April 2013 editL2j2 (talk | contribs)115 editsNo edit summary← Previous edit Latest revision as of 16:18, 17 October 2024 edit undoAndrewWTaylor (talk | contribs)Extended confirmed users, Pending changes reviewers11,529 editsm Mills' formula: remove "Note that" per MOSTag: 2017 wikitext editor 
(487 intermediate revisions by more than 100 users not shown)
Line 1: Line 1:
{{short description|Formula whose values are the prime numbers}}
In ], a '''formula for primes''' is a ] generating the ]s, 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.


==Formulas based on Wilson's theorem==


A simple formula is
:<math>f(n) = \left\lfloor \frac{n! \bmod (n+1)}{n} \right\rfloor (n-1) + 2</math>
for positive ] <math>n</math>, where <math>\lfloor\ \rfloor</math> is the ], which rounds down to the nearest integer.
By ], <math>n+1</math> is prime if and only if <math>n! \equiv n \pmod{n+1}</math>. Thus, when <math>n+1</math> is prime, the first factor in the product becomes one, and the formula produces the prime number <math>n+1</math>. But when <math>n+1</math> is not prime, the first factor becomes zero and the formula produces the prime number 2.<ref>{{citation
| last = Mackinnon | first = Nick
| date = June 1987
| doi = 10.2307/3616496
| issue = 456
| pages = 113–114
| journal = ]
| title = Prime number formulae
| volume = 71
| jstor = 3616496
| s2cid = 171537609
}}.</ref>
This formula is not an efficient way to generate prime numbers because evaluating <math>n! \bmod (n+1)</math> requires about <math>n-1</math> multiplications and reductions modulo <math>n+1</math>.


In 1964, Willans gave the formula
In ], a '''formula for primes''' is a formula generating the ]s, exactly and without exception. No such formula which is easily ] is presently known. A number of constraints are known: what such a "formula" can and cannot be.
:<math>p_n = 1 + \sum_{i=1}^{2^n} \left\lfloor \left(\frac{n}{\sum_{j=1}^i \left\lfloor\left(\cos \frac{(j-1)! + 1}{j} \pi\right)^2\right\rfloor }\right)^{1/n} \right\rfloor</math>
for the <math>n</math>th prime number <math>p_n</math>.<ref>{{citation
| last = Willans | first = C. P.
| date = December 1964
| doi = 10.2307/3611701
| issue = 366
| pages = 413–415
| journal = ]
| title = On formulae for the <math>n</math>th prime number
| volume = 48
| jstor = 3611701
| s2cid = 126149459
}}.</ref>
This formula reduces to<ref>{{citation
| last1 = Neill | first1 = T. B. M.
| last2 = Singer | first2 = M.
| date = October 1965
| doi = 10.2307/3612863
| issue = 369
| jstor = 3612863
| journal = ]
| pages = 303–303
| title = To the Editor, ''The Mathematical Gazette''
| volume = 49}}</ref><ref>{{citation
| last1 = Goodstein | first1 = R. L.
| last2 = Wormell | first2 = C. P.
| date = February 1967
| doi = 10.2307/3613607
| issue = 375
| journal = ]
| jstor = 3613607
| pages = 35–38
| title = Formulae For Primes
| volume = 51}}</ref> <math>p_n = 1 + \sum_{i=1}^{2^n}</math>; that is, it tautologically defines <math>p_n</math> as the smallest integer ''m'' for which the ] <math>\pi(m)</math> is at least ''n''. This formula is also not efficient. In addition to the appearance of <math>(j-1)!</math>, it computes <math>p_n</math> by adding up <math>p_n</math> copies of <math>1</math>; for example, <math>p_5 = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + \dots + 0 = 11</math>.


The articles ''What is an Answer?'' by ] (1982)<ref>{{citation
==Prime formulas and polynomial functions==
| last = Wilf | first = Herbert S. | author-link = Herbert Wilf
| doi = 10.2307/2321713
| issue = 5
| journal = ]
| jstor = 2321713
| mr = 653502
| pages = 289–292
| title = What is an answer?
| volume = 89
| year = 1982}}</ref> and ''Formulas for Primes'' by ] (1983)<ref>{{citation
| last = Dudley | first = Underwood | author-link = Underwood Dudley
| doi = 10.2307/2690261
| issue = 1
| journal = ]
| jstor = 2690261
| mr = 692169
| pages = 17–22
| title = Formulas for primes
| volume = 56
| year = 1983}}</ref> have further discussion about the worthlessness of such formulas.


==Formula based on a system of Diophantine equations==
It is known that no non-] ] function ''P''(''n'') with integer coefficients exists that evaluates to a ] for all integers ''n''. The proof is as follows: Suppose such a polynomial existed. Then ''P''(1) would evaluate to a prime ''p'', so <math>P(1) \equiv 0 \pmod p</math>. But for any ''k'', <math>P(1+kp) \equiv 0 \pmod p</math> also, so <math>P(1+kp)</math> cannot also be prime (as it would be divisible by ''p'') unless it were ''p'' itself, but the only way <math>P(1+kp) = P(1)</math> for all ''k'' is if the polynomial function is constant.
Because the set of primes is a ], by ], it can be obtained from a system of ]s. {{Harvtxt|Jones|Sato|Wada|Wiens|1976}} found an explicit set of 14 Diophantine equations in 26 variables, such that a given number ''k''&thinsp;+&thinsp;2 is prime ] that system has a solution in nonnegative integers:<ref>{{citation | first1=James P. | last1=Jones | first2=Daihachiro | last2=Sato | first3=Hideo | last3=Wada | first4=Douglas | last4=Wiens | author4-link=Douglas Wiens | url=http://mathdl.maa.org/mathDL/?pa=content&sa=viewDocument&nodeId=2967&pf=1 | year=1976 | title=Diophantine representation of the set of prime numbers | journal=] | volume=83 | pages=449–464 | doi=10.2307/2318339 | jstor=2318339 | issue=6 | publisher=Mathematical Association of America | url-status=dead | archive-url=https://web.archive.org/web/20120224013618/http://mathdl.maa.org/mathDL/?pa=content&sa=viewDocument&nodeId=2967&pf=1 | archive-date=2012-02-24 }}.</ref>


: <math>\alpha_0= wz + h + j - q = 0</math>
The same reasoning shows an even stronger result: no non-constant polynomial function ''P''(''n'') exists that evaluates to a prime number for ] integers ''n''.


: <math>\alpha_1 = (gk + 2g + k + 1)(h + j) + h - z = 0</math>
] first noticed (in 1772) that the ]
:''P''(''n'') = ''n''<sup>2</sup> - ''n'' + 41
is prime for all ]s less than 41. The primes for ''n'' = 1, 2, 3... are 41, 43, 47, 53, 61, 71... The differences between the terms are 2, 4, 6, 8, 10... For ''n'' = 41, it produces a square number, 1681, which is equal to 41×41, the smallest ] for this formula. If 41 divides ''n'' it divides ''P(n)'' too. The phenomenon is related to the ], which is also implicitly quadratic, and the ];
this polynomial is related to the ] <math>163=4\cdot 41-1</math>, and there are analogous polynomials for <math>p=2, 3, 5, 11, \text{ and } 17</math>, corresponding to other Heegner numbers.


: <math>\alpha_2= 16(k + 1)^3(k + 2)(n + 1)^2 + 1 - f^2 = 0</math>
It is known, based on ], that linear polynomial functions <math>L(n) = an + b</math> produce infinitely many primes as long as ''a'' and ''b'' are ] (though no such function will assume prime values for all values of ''n''). Moreover, the ] says that for any ''k'' there exists a pair of ''a'' and ''b'' with the property that <math>L(n) = an+b</math> is prime for any ''n'' from 0 to ''k''&nbsp;−&nbsp;1. However, the best known result of such type is for ''k'' = 26:
:43142746595714191 + 5283234035979900''n'' is prime for all ''n'' from 0 to 25 {{harv|Andersen|2010}}.


: <math>\alpha_3= 2n + p + q + z - e = 0</math>
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 ].


: <math>\alpha_4= e^3(e + 2)(a + 1)^2 + 1 - o^2 = 0</math>
==Formula based on a system of Diophantine equations==


: <math>\alpha_5=(a^2 - 1)y^2 + 1 - x^2 = 0</math>
A system of 14 ]s in 26 variables can be used to obtain a Diophantine representation of the set of all primes. {{Harvtxt|Jones|Sato|Wada|Wiens|1976}} proved that a given number ''k''&nbsp;+&nbsp;2 is prime ] the following system of 14 Diophantine equations has a solution in the ]s:


: α<sub>0</sub> = <math> wz + h + j - q </math> = 0 : <math>\alpha_6= 16r^2y^4(a^2 - 1) + 1 - u^2 = 0</math>


: α<sub>1</sub> = <math> (gk + 2g + k + 1)(h + j) + h - z </math> = 0 : <math>\alpha_7= n + \ell + v - y = 0</math>


: α<sub>2</sub> = <math> 16(k + 1)^3(k + 2)(n + 1)^2 + 1 - f^2 </math> = 0 : <math>\alpha_8= (a^2 - 1)\ell^2 + 1 - m^2 = 0</math>


: α<sub>3</sub> = <math> 2n + p + q + z - e </math> = 0 : <math>\alpha_9= ai + k + 1 - \ell - i = 0</math>


: α<sub>4</sub> = <math> e^3(e + 2)(a + 1)^2 + 1 - o^2 </math> = 0 : <math>\alpha_{10}= ((a + u^2(u^2 - a))^2 - 1)(n + 4dy)^2 + 1 - (x + cu)^2 = 0</math>


: α<sub>5</sub> = <math> (a^2 - 1)y^2 + 1 - x^2 </math> = 0 : <math>\alpha_{11}= p + \ell(a - n - 1) + b(2an + 2a - n^2 - 2n - 2) - m= 0 </math>


: α<sub>6</sub> = <math> 16r^2y^4(a^2 - 1) + 1 - u^2 </math> = 0 : <math>\alpha_{12}= q + y(a - p - 1) + s(2ap + 2a - p^2 - 2p - 2) - x = 0</math>


: α<sub>7</sub> = <math> n + l + v - y </math> = 0 :<math>\alpha_{13}= z + p\ell(a - p) + t(2ap - p^2 - 1) - pm = 0</math>


: α<sub>8</sub> = <math> (a^2 - 1)l^2 + 1 - m^2 </math> = 0 The 14 equations ''α''<sub>0</sub>, …, ''α''<sub>13</sub> can be used to produce a prime-generating polynomial inequality in 26 variables:


: α<sub>9</sub> = <math> ai + k + 1 - l - i </math> = 0 :<math> (k+2)(1-\alpha_0^2-\alpha_1^2-\cdots-\alpha_{13}^2) > 0.</math>


That is,
: α<sub>10</sub> = <math> ((a + u^2(u^2 - a))^2 - 1)(n + 4dy)^2 + 1 - (x + cu)^2 </math> = 0


: <math>
: α<sub>11</sub> = <math> p + l(a - n - 1) + b(2an + 2a - n^2 - 2n - 2) - m </math> = 0
\begin{align}
& (k+2) (1 - {} \\
& ^2 - {} \\
& ^2 - {} \\
& ^2 - {} \\
& ^2 - {} \\
& ^2 - {} \\
& ^2 - {} \\
& ^2 - {} \\
& ^2 - {} \\
& ^2 - {} \\
& ^2 - {} \\
& ^2 - {} \\
& ^2 - {} \\
& ^2 - {} \\
& ^2) \\
& > 0
\end{align}
</math>


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.
: α<sub>12</sub> = <math> q + y(a - p - 1) + s(2ap + 2a - p^2 - 2p - 2) - x </math> = 0


A general theorem of ] 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.<ref>{{citation | last = Matiyasevich | first = Yuri V. | author-link = Yuri Matiyasevich | year=1999 | chapter = Formulas for Prime Numbers | chapter-url=https://books.google.com/books?id=oLKlk5o6WroC&pg=PA13 | editor1-first=Serge | editor1-last = Tabachnikov | editor-link1=Sergei Tabachnikov| title = Kvant Selecta: Algebra and Analysis | volume = II | publisher = ] | isbn = 978-0-8218-1915-9 | pages=13–24}}.</ref> Hence, there is a prime-generating polynomial inequality as above with only 10 variables. However, its degree is large (in the order of 10<sup>45</sup>). On the other hand, there also exists such a set of equations of degree only 4, but in 58 variables.<ref>{{citation | doi=10.2307/2273588 | first=James P. | last=Jones | year=1982 | title=Universal diophantine equation | journal=Journal of Symbolic Logic | volume=47 | issue=3 | pages=549–571| jstor=2273588 | s2cid=11148823 }}.</ref>
: α<sub>13</sub> = <math> z + pl(a - p) + t(2ap - p^2 - 1) - pm </math> = 0


==Mills' formula==
The 14 equations α<sub>0</sub>, …, α<sub>13</sub> can be used to produce a prime-generating polynomial inequality in 26 variables:
The first such formula known was established by {{harvs|first=W. H.|last=Mills|year=1947|txt}}, who proved that there exists a ] ''A'' such that, if


:<math> (k+2)(1-\alpha_0^2-\alpha_1^2-\cdots-\alpha_{13}^2) > 0 </math> :<math>d_n = A^{3^{n}}</math>


then
i.e.:


:<math> (k+2) (1 - </math> :<math>\left \lfloor d_n \right \rfloor = \left \lfloor A^{3^{n}} \right \rfloor</math>
:<math> ^2 - </math>
:<math> ^2 - </math>
:<math> ^2 - </math>
:<math> ^2 - </math>
:<math> ^2 - </math>
:<math> ^2 - </math>
:<math> ^2 - </math>
:<math> ^2 - </math>
:<math> ^2 - </math>
:<math> ^2 - </math>
:<math> ^2 - </math>
:<math> ^2 - </math>
:<math> ^2 - </math>
:<math> ^2) </math>
:<math> > 0 </math>


is a prime number for all positive integers ''n''.<ref>{{citation|first=W. H.|last=Mills|title=A prime-representing function|journal=]|volume=53|year=1947|page=604|doi=10.1090/S0002-9904-1947-08849-2|issue=6|url = https://www.ams.org/journals/bull/1947-53-06/S0002-9904-1947-08849-2/S0002-9904-1947-08849-2.pdf|doi-access=free}}.</ref> If the ] is true, then the smallest such ''A'' has a value of around 1.3063778838630806904686144926... {{OEIS|id=A051021}} and is known as ].<ref>{{citation|first1=Chris K.|last1=Caldwell|first2=Yuanyou|last2=Cheng|title=Determining Mills' Constant and a Note on Honaker's Problem|journal=Journal of Integer Sequences|volume=8|year=2005|at=Article 05.4.1.|url=https://cs.uwaterloo.ca/journals/JIS/VOL8/Caldwell/caldwell78.html}}</ref> This value gives rise to the primes <math>\left \lfloor d_1 \right \rfloor = 2</math>, <math>\left \lfloor d_2 \right \rfloor = 11</math>, <math>\left \lfloor d_3 \right \rfloor = 1361</math>, ... {{OEIS|id=A051254}}. Very little is known about the constant ''A'' (not even whether it is ]). This formula has no practical value, because there is no known way of calculating the constant without finding primes in the first place.
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.


There is nothing special about the ] in the formula. Tóth proved that there also exists a constant <math>B</math> such that
A general theorem of ] 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. Hence, there is a prime-generating polynomial as above with only 10 variables. However, its degree is large (in the order of 10<sup>45</sup>). On the other hand, there also exists such a set of equations of degree only 4, but in 58 variables.{{harv|Jones|1982}}


:<math> \lceil B^{r^{n}} \rceil</math>
==Formulas using the floor function==


is also prime-representing for <math>r>2.106\ldots</math>.<ref>{{citation|first=László|last=Tóth|title=A Variation on Mills-Like Prime-Representing Functions|journal=Journal of Integer Sequences|volume=20|year=2017|issue=17.9.8|arxiv=1801.08014|url=https://cs.uwaterloo.ca/journals/JIS/VOL20/Toth2/toth32.pdf}}.</ref>
Using the ] <math>\lfloor x\rfloor</math> (defined to be the largest integer less than or equal to the ] ''x''), one can construct several formulas that take only prime numbers as values for all positive integers ''n''.


In the case <math>r=3</math>, the value of the constant <math>B</math> begins with 1.24055470525201424067... The first few primes generated are:
===Mills's formula===


:<math>2, 7, 337, 38272739, 56062005704198360319209, </math>
The first such formula known was established in 1947 by ], who proved that there exists a ] ''A'' such that
:<math> 176199995814327287356671209104585864397055039072110696028654438846269, \ldots</math>


''Without'' assuming the Riemann hypothesis, Elsholtz developed several prime-representing ] similar to those of Mills. For example, if <math>A = 1.00536773279814724017 \ldots</math>, then <math>\left\lfloor A^{10^{10n}} \right\rfloor</math> is prime for all positive integers <math>n</math>. Similarly, if <math>A = 3.8249998073439146171615551375 \ldots</math>, then <math>\left\lfloor A^{3^{13n}} \right\rfloor</math> is prime for all positive integers <math>n</math>.<ref name="Elsholtz">{{citation
:<math>\lfloor A^{3^{n}}\;\rfloor</math>
| doi = 10.1080/00029890.2020.1751560
| first = Christian | last = Elsholtz
| title = Unconditional Prime-Representing Functions, Following Mills
| journal = American Mathematical Monthly
| volume = 127
| issue = 7
| pages = 639–642
| publisher = ]
| location = Washington, DC
| year = 2020
| arxiv = 2004.01285| s2cid = 214795216 }}
</ref>


==Wright's formula==
is a prime number for all positive integers ''n''. If the ] is true, then the smallest such ''A'' has a value of around 1.3063... and is known as ]. This formula has no practical value, because very little is known about the constant (not even whether it is ]), and there is no known way of calculating the constant without finding primes in the first place.
Another ]ally growing prime-generating formula similar to Mills' comes from a theorem of ]. He proved that there exists a real number ''α'' such that, if
:<math>g_0 = \alpha</math> and
:<math>g_{n+1} = 2^{g_n}</math> for <math>n \ge 0</math>,
then
:<math>\left \lfloor g_n \right \rfloor = \left \lfloor 2^{\dots^{2^{2^\alpha}}} \right \rfloor </math>
is prime for all <math>n \ge 1</math>.<ref>{{citation |author=E. M. Wright |title=A prime-representing function |journal=] |volume=58 |issue=9 |year=1951 |pages=616–618 |jstor=2306356 |doi= 10.2307/2306356}}</ref>
Wright gives the first seven decimal places of such a constant: <math>\alpha = 1.9287800</math>. This value gives rise to the primes <math>\left \lfloor g_1 \right \rfloor = \left \lfloor 2^{\alpha} \right \rfloor = 3 </math>, <math>\left \lfloor g_2 \right \rfloor = 13 </math>, and <math>\left \lfloor g_3 \right \rfloor = 16381 </math>. <math>\left \lfloor g_4 \right \rfloor</math> is ], and so is not prime. However, with <math>\alpha = 1.9287800 + 8.2843 \cdot 10^{-4933}</math>, <math>\left \lfloor g_1 \right \rfloor</math>, <math>\left \lfloor g_2 \right \rfloor</math>, and <math>\left \lfloor g_3 \right \rfloor</math> are unchanged, while <math>\left \lfloor g_4 \right \rfloor</math> is a prime with 4932 digits.<ref>{{cite arXiv |last=Baillie |first=Robert |eprint=1705.09741v3 |title=Wright's Fourth Prime |class=math.NT |date=5 June 2017|mode=cs2 }}</ref> This ] of primes cannot be extended beyond <math>\left \lfloor g_4 \right \rfloor</math> without knowing more digits of <math>\alpha</math>. Like Mills' formula, and for the same reasons, Wright's formula cannot be used to find primes.


==A function that represents all primes==
===Converting the sieve of Eratosthenes to prime number formulas===
Given the constant <math>f_1 = 2.920050977316\ldots</math> {{OEIS|A249270}}, for <math>n \ge 2</math>, define the sequence
There is another, quite different formula discovered by Sebastián Martín-Ruiz {{harv|Rivera|n.d.}} and proved with ] {{harv|Martin-Ruiz|Sondow|2002}}:
{{NumBlk|:|<math>
:<math>\pi(k) = k - 1 + \sum_{j=1}^k \left\lfloor {2 \over j} \left(1 + \sum_{s=1}^{\left\lfloor\sqrt{j}\right\rfloor} \left(\left\lfloor{ j-1 \over s}\right\rfloor - \left\lfloor{j \over s}\right\rfloor\right) \right)\right\rfloor </math>
f_n = \left\lfloor f_{n-1} \right\rfloor
(f_{n-1} - \left\lfloor f_{n-1} \right\rfloor + 1 )
</math>|{{EquationRef|1}}}}
where <math>\left\lfloor\ \right\rfloor</math> is the ].
Then for <math>n \ge 1</math>, <math>\left\lfloor f_{n} \right\rfloor</math> equals the <math>n</math>th prime:
<math>\left\lfloor f_1 \right\rfloor = 2</math>,
<math>\left\lfloor f_2 \right\rfloor = 3</math>,
<math>\left\lfloor f_3 \right\rfloor = 5</math>, etc.
<ref name="FridmanEtAl">{{citation
| doi = 10.1080/00029890.2019.1530554
| first1=Dylan | last1=Fridman | first2=Juli | last2=Garbulsky | first3=Bruno | last3=Glecer
| first4=James | last4=Grime | first5=Massi | last5=Tron Florentin
| title = A Prime-Representing Constant
| journal = American Mathematical Monthly
| volume = 126
| issue = 1
| pages = 70–73
| publisher = ]
| location = Washington, DC
| year = 2019| arxiv=2010.15882 | s2cid=127727922 }}
</ref>
The initial constant <math>f_1 = 2.920050977316</math> given in the article is precise enough for equation ({{EquationNote|1}}) to generate the primes through 37, the <math>12</math>th prime.


The ''exact'' value of <math>f_1</math> that generates ''all'' primes is given by the rapidly-converging ]
Note the following equalities:
:<math>
f_1 = \sum_{n=1}^\infty \frac{p_n - 1}{P_n}
= \frac{2 - 1}{1} + \frac{3 - 1}{2} + \frac{5 - 1}{2 \cdot 3} + \frac{7 - 1}{2 \cdot 3 \cdot 5} + \cdots,
</math>
where <math>p_n</math> is the <math>n</math>th prime, and <math>P_n</math> is the product of all primes less than <math>p_n</math>. The more digits of <math>f_1</math> that we know, the more primes equation ({{EquationNote|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:
: <math>f_1 \simeq 2.920050977316134712092562917112019.</math>
This has enough digits for equation ({{EquationNote|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, <math>f_1</math>, which in this case requires a longer list of primes in its calculation.
:<math>\left\lfloor{ j \over s}\right\rfloor - \left\lfloor{j-1 \over s}\right\rfloor = \begin{cases}
1 & s \text{ divides } j \\
0 & s \text{ does not divide } j
\end{cases} </math>


==Plouffe's formulas==
:<math>2\sum_{s=1}^{\left\lfloor\sqrt{j}\right\rfloor} \left(\left\lfloor{ j \over s}\right\rfloor - \left\lfloor{j-1 \over s}\right\rfloor\right) = \text{number of divisors of } j </math>
In 2018 ] ]d a set of formulas for primes. Similarly to the formula of Mills, they are of the form


:<math>\left\{a_0^{r^n}\right\}</math>
:<math>\left\lfloor {-1 \over j} \sum_{s=2}^{\left\lfloor\sqrt{j}\right\rfloor} \left(\left\lfloor{ j \over s}\right\rfloor - \left\lfloor{j-1 \over s}\right\rfloor\right)\right\rfloor=\begin{cases}
0 & j \text{ is prime} \\
-1 & j \text{ is composite}
\end{cases}</math>


where <math>\{\ \}</math> is the function rounding to the nearest integer. For example, with <math>a_0\approx 43.80468771580293481</math> and <math>r=5/4</math>, this gives 113, 367, 1607, 10177, 102217... {{OEIS|A323176}}. Using <math>a_0=10^{500}+961+\varepsilon</math> and <math>r=1.01</math> with <math>\varepsilon</math> a certain number between 0 and one half, Plouffe found that he could generate a sequence of 50 ] (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.<ref>{{citation
:<math>\operatorname{IsPrime}(j)=1+\left\lfloor {-1 \over j} \sum_{s=2}^{\left\lfloor\sqrt{j}\right\rfloor} \left(\left\lfloor{ j \over s}\right\rfloor - \left\lfloor{j-1 \over s}\right\rfloor\right) \right\rfloor=\begin{cases}
| last = Steckles | first = Katie
1 & j \text{ is prime} \\
| date = January 26, 2019
0 & j \text{ is composite}
| journal = New Scientist
\end{cases}</math>
| title = Mathematician's record-beating formula can generate 50 prime numbers
| url = https://www.newscientist.com/article/mg24132143-200-mathematicians-record-beating-formula-can-generate-50-prime-numbers/}}</ref><ref>{{cite arXiv |last1=Simon Plouffe |title=A set of formulas for primes |eprint=1901.01849 |class=math.NT |year=2019 |mode=cs2}} As of January 2019, the number he gives in the appendix for the 50th number generated is actually the 48th.</ref>


==Prime formulas and polynomial functions==
:<math>\pi(k) =\sum_{j=2}^k \operatorname{IsPrime}(j),</math>


It is known that no non-] 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 <math>P(1) \equiv 0 \pmod p</math>. But for any integer ''k'', <math>P(1+kp) \equiv 0 \pmod p</math> also, so <math>P(1+kp)</math> cannot also be prime (as it would be divisible by ''p'') unless it were ''p'' itself. But the only way <math>P(1+kp) = P(1) = p</math> for all ''k'' is if the polynomial function is constant.
where <math>\pi(k)</math> is the ].
The same reasoning shows an even stronger result: no non-constant polynomial function ''P''(''n'') exists that evaluates to a prime number for ] integers ''n''.


] first noticed (in 1772) that the ]
===Converting primality tests to prime number formulas===


:<math>P(n) = n^2 + n + 41</math>
Any ] can be used as the basis for a prime number formula. In effect, a test for the primality of ''n'' is a computation of the function IsPrime(''n''), defined by:
:<math>\operatorname{IsPrime}(n) =
\begin{cases}
1 & n \text{ prime} \\
0 & n \text{ composite}
\end{cases}
</math>
If the primality test is given by a condition on some formula involving <math>n,</math> then that formula gives a formula for IsPrime(''n''). Using a product,
:<math>\prod_{k=2}^{n} \prod_{l=2}^{n} (n-kl) = 0\text{ if and only if n is not a prime (and integer more than 1)}</math>
For a prime <math>n \ge 2</math>,the product above is not 0. So,
:<math>\operatorname{IsPrime}(n) =
\operatorname{abs} \left( \operatorname{sgn} \left( \prod_{k=2}^{n} \prod_{l=2}^{n} (n-kl)\right) \right)</math>
where n is more than 1. However, the product is very large or very small where n is a prime so
:<math>\operatorname{IsPrime}(n) =
\operatorname{abs}\left( \prod_{k=2}^{n} \prod_{l=2}^{n} \operatorname{sgn} (n-kl)\right).</math>
Moreover, we need not calculate product up to k=l=n.
:<math>\operatorname{IsPrime}(n) =
\operatorname{abs}\left( \prod_{k=2}^{\lfloor\frac{n}{2}\rfloor } \prod_{l=2}^{\operatorname{min}(k,\lfloor\frac{n}{k}\rfloor)} \operatorname{sgn} (n-kl)\right).</math>
] states that ''n'' is prime ] it divides <math>(n - 1)! + 1.</math> To express this by an explicit formula, two intermediate functions are introduced:
:<math>r(n) = \frac{(n - 1)! + 1}{n},</math>
:<math>\operatorname{IsInteger}(x) =
\begin{cases}
1 & x \text{ is an integer} \\
0 & x \text{ is not an integer}
\end{cases}
</math>
Then Wilson's theorem says that
:<math>\operatorname{IsPrime}(n) = \operatorname{IsInteger}\bigl(r(n)\bigr).</math>
This can be further specified by an explicit formula for IsInteger(''x''). Some options are:
:<math>\operatorname{IsInteger}(x) = \lfloor x\rfloor + \lfloor -x \rfloor + 1</math>
:<math>\operatorname{IsInteger}(x) = \left\lfloor \frac{\lfloor x \rfloor}{x} \right\rfloor</math>
:<math>\operatorname{IsInteger}(x) = \lfloor \cos^2(\pi x) \rfloor</math> : formula by C. P. Willans {{harv|Bowyer|n.d.}}
Then, for example, taking the first option gives a formula for IsPrime(''n'') using Wilson's theorem:
:<math>\operatorname{IsPrime}(n) =
\left\lfloor \frac{(n - 1)! + 1}{n} \right\rfloor + \left\lfloor -\frac{(n - 1)! + 1}{n} \right\rfloor + 1
</math>
Not using the function IsInteger,
:<math>\operatorname{IsPrime}(n) = \operatorname{abs}\left(\prod_{k=1}^{(n-1)!} \operatorname{sgn}((n-1)!+1-kn)\right).</math>
Once IsPrime(''n'') can be computed, the ] <math>\pi(n)</math> can as well, since by definition
:<math>\pi(n) = \text{number of primes less than or equal to } n = \sum_{k = 1}^n \operatorname{IsPrime}(k).</math>
<math>\pi(n)</math> can then compute a function testing whether a given integer ''n'' is the ''m''<sup>th</sup> prime:
:<math>\operatorname{IsNthPrime}(n,m) =
\operatorname{IsPrime}(n) * \operatorname{IsZero}(\pi(n) - m) =
\begin{cases}
1 & n \text{ is the } m^\text{th} \text{ prime} \\
0 & \text{otherwise}
\end{cases}
</math>
The function IsZero(''x'') can likewise be expressed by a formula:
:<math>\operatorname{IsZero}(n) = \left\lfloor {1 \over {1+|n|}}\right\rfloor,</math>


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 ], 1681, which is equal to 41&thinsp;×&thinsp;41, the smallest ] 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'' +&thinsp;1) + 41, if 41 divides ''n'' +&thinsp;1 instead, it also divides ''P''(''n''). The phenomenon is related to the ], which is also implicitly quadratic, and the ]; this polynomial is related to the ] <math>163=4\cdot 41-1</math>. There are analogous polynomials for <math>p=2, 3, 5, 11 \text{ and } 17</math> (the ]), corresponding to other Heegner numbers.
Finally, the IsNthPrime(<math>n,m</math>) function can be used to produce a formula for the ''n''<sup>th</sup> prime:
:<math>p_n = \sum_{m = 1}^{2^n} m * \operatorname{IsNthPrime}(m,n).</math>
The upper bound 2<sup>''n''</sup> comes from ], which implies that there is a sequence of primes
:<math>2 = p_1 < p_2 < \dots < p_n,</math> where <math>p_{i + 1} < 2 p_i. </math> Thus, <math>p_n < 2^n.</math>
Substituting the formulas above and applying Wilson's theorem gives a formula for <math>p_n</math> involving the arithmetic operations and the floor function. Other such formulas are:
:<math>p_n = 1 + \sum_{k=1}^{2^n} \left\lfloor \left\lfloor { n \over 1 + \pi(k) } \right\rfloor^{1 \over n} \right\rfloor.</math>
in which the following equality is important:
:<math>\left\lfloor \left\lfloor { n \over 1 + \pi(k) } \right\rfloor^{1 \over n} \right\rfloor={\begin{cases}
1, & \text{if } \pi(k) \le n-1 \\
0, & \text{if } \pi(k) > n-1
\end{cases}} </math>
and
:<math>p_n = 1 + \sum_{k=1}^{2(\lfloor n \ln(n)\rfloor+1)} \left(1 - \left\lfloor{\pi(k) \over n} \right\rfloor\right)
</math>
by Sebastián Martín-Ruiz and proved with Jonathan Sondow {{harv|Martin-Ruiz|Sondow|2002}}. A similar formula for <math>p_n</math> was given earlier by Stephen Regimbal {{harv|Regimbal|1975}}.


Given a positive integer ''S'', there may be infinitely many ''c'' such that the expression ''n''<sup>2</sup> + ''n'' + ''c'' is always coprime to ''S''. The integer ''c'' may be negative, in which case there is a delay before primes are produced.
==Recurrence relation==

It is known, based on ], that linear polynomial functions <math>L(n) = an + b</math> produce infinitely many primes as long as ''a'' and ''b'' are ] (though no such function will assume prime values for all values of ''n''). Moreover, the ] says that for any ''k'' there exists a pair of ''a'' and ''b'', with the property that <math>L(n) = an+b</math> is prime for any ''n'' from 0 through ''k''&nbsp;−&nbsp;1. However, {{as of|2020|lc=y|post=,}} the best known result of such type is for ''k'' = 27:

:<math>224584605939537911 + 18135696597948930n</math>

is prime for all ''n'' from 0 through 26.<ref>, from ]. The AP27 is listed in .</ref> It is not even known whether there exists a ] of degree at least 2, that assumes an infinite number of values that are prime; see ].

==Possible formula using a recurrence relation==
Another prime generator is defined by the ] Another prime generator is defined by the ]
:<math> a_n = a_{n-1} + \operatorname{gcd}(n,a_{n-1}), \quad a_1 = 7, </math> :<math> a_n = a_{n-1} + \gcd(n,a_{n-1}), \quad a_1 = 7, </math>
where gcd(''x'', ''y'') denotes the ] of ''x'' and ''y''. The sequence of differences ''a''<sub>''n'' + 1</sub> − ''a<sub>n</sub>'' starts with 1, 1, 1, 5, 3, 1, 1, 1, 1, 11, 3, 1, 1 {{OEIS|id=A132199}}. {{harvtxt|Rowland|2008}} proved that this sequence contains only ones and prime numbers. where gcd(''x'', ''y'') denotes the ] of ''x'' and ''y''. The sequence of differences ''a''<sub>''n''+1</sub> − ''a<sub>n</sub>'' 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, ... {{OEIS|id=A132199}}. {{harvtxt|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'' +&thinsp;1, ''a<sub>n</sub>'') are always ] and so never equal to 2. 587 is the smallest prime (other than 2) not appearing in the first 10,000 outcomes that are different from 1. Nevertheless, in the same paper it was conjectured to contain all odd primes, even though it is rather inefficient.<ref>{{Citation | last1=Rowland | first1=Eric S. | title=A Natural Prime-Generating Recurrence | url=http://www.cs.uwaterloo.ca/journals/JIS/VOL11/Rowland/rowland21.html | year=2008 | journal=Journal of Integer Sequences | volume=11 | issue=2 | pages=08.2.8 | bibcode=2008JIntS..11...28R|arxiv = 0710.3217 }}.</ref>

Note that there is a trivial program that enumerates all and only the prime numbers, as well as ], so such recurrence relations are more a matter of curiosity than of any practical use.


==See also== ==See also==
* ] * ]


==References== ==References==
{{Reflist}}
<div class="references-small">

* {{citation | first1=Jens Kruse | last1=Andersen | year=2010 | title=Primes in Arithmetic Progression Records | url=http://users.cybercity.dk/~dsl522332/math/aprecords.htm | accessdate=2010-04-13 }}.
==Further reading==
* {{citation | first1=Adrian | last1=Bowyer | year=n.d. | pages=11761 | title=Formulae for Primes | journal=Eprint arXiv:math/0611761 | url=http://people.bath.ac.uk/ensab/Primes/ | accessdate=2008-07-09 | bibcode=2006math.....11761F |arxiv = math/0611761 }}.
* {{citation | first1=James P. | last1=Jones | first2=Daihachiro | last2=Sato | first3=Hideo | last3=Wada | first4=Douglas | last4=Wiens | author4-link=Douglas Wiens | url = http://mathdl.maa.org/mathDL/?pa=content&sa=viewDocument&nodeId=2967&pf=1 | year=1976 | title=Diophantine representation of the set of prime numbers | journal=] | volume=83 | pages=449–464 | doi=10.2307/2318339 | jstor=2318339 | issue=6 | publisher=Mathematical Association of America}}. *{{Citation | doi=10.2307/2690354 | last1=Regimbal | first1=Stephen | title=An explicit Formula for the k-th prime number | jstor=2690354 | year=1975 | journal=Mathematics Magazine | volume=48 | pages=230–232 | issue=4 | publisher=Mathematical Association of America}}.
*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,
* {{citation | doi=10.2307/2273588 | first=James P. | last=Jones | year=1982 | title=Universal diophantine equation | journal=Journal of Symbolic Logic | volume=47 | issue=3 | pages=549–571}}.
* {{cite arxiv | first1=Sebastian | last1=Martin-Ruiz | first2=Jonathan | last2=Sondow | year=2002 | title=Formulas for ''π''(''n'') and the ''n''th prime | eprint=math/0210312| }}.
* {{Citation | doi=10.2307/2690354 | last1=Regimbal | first1=Stephen | title=An explicit Formula for the k-th prime number | jstor=2690354 | year=1975 | journal=Mathematics Magazine | volume=48 | pages=230–232 | issue=4 | publisher=Mathematical Association of America}}.
* {{citation | first1=Carlos | last1=Rivera | year=n.d. | title=Problem 38. Sebastián Martín Ruiz- Prime formulas | url=http://www.primepuzzles.net/problems/prob_038.htm | accessdate=2008-07-09 }}.
* {{Citation | last1=Rowland | first1=Eric S. | title=A Natural Prime-Generating Recurrence | url=http://www.cs.uwaterloo.ca/journals/JIS/VOL11/Rowland/rowland21.html | year=2008 | journal=Journal of Integer Sequences | volume=11 | pages=08.2.8 | bibcode=2008JIntS..11...28R|arxiv = 0710.3217 }}.
* {{citation | last = Matiyasevich | first = Yuri V. | authorlink = Yuri Matiyasevich | title = Formulas for Prime Numbers | journal = Eprint arXiv:math/0611761 | pages = 11761 | year = 2006 | bibcode = 2006math.....11761F|arxiv = math/0611761 }} ({{citation | first = Serge | last = Tabachnikov | title = Kvant selecta: algebra and analysis | volume = 1 | publisher = AMS Bookstore | isbn = 978-0-8218-1915-9}}, ).
</div>
{{reflist}}


==External links== ==External links==
* {{MathWorld|urlname=PrimeFormulas|title=Prime Formulas}} * {{MathWorld2|urlname=PrimeFormulas|title=Prime Formulas|urlname2=Prime-GeneratingPolynomial|title2=Prime-Generating Polynomial}}
* {{MathWorld|urlname=Prime-GeneratingPolynomial|title=Prime-Generating Polynomial}}
* {{MathWorld|urlname=MillsConstant|title=Mill's Constant}}
*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.&nbsp;49–52. Page , , , , .


{{Prime number classes}} {{Prime number classes}}

Latest revision as of 16:18, 17 October 2024

Formula whose values are the prime numbers

In number theory, a formula for primes is a formula generating the prime 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.

Formulas based on Wilson's theorem

A simple formula is

f ( n ) = n ! mod ( n + 1 ) n ( n 1 ) + 2 {\displaystyle f(n)=\left\lfloor {\frac {n!{\bmod {(}}n+1)}{n}}\right\rfloor (n-1)+2}

for positive integer n {\displaystyle n} , where   {\displaystyle \lfloor \ \rfloor } is the floor function, which rounds down to the nearest integer. By Wilson's theorem, n + 1 {\displaystyle n+1} is prime if and only if n ! n ( mod n + 1 ) {\displaystyle n!\equiv n{\pmod {n+1}}} . Thus, when n + 1 {\displaystyle n+1} is prime, the first factor in the product becomes one, and the formula produces the prime number n + 1 {\displaystyle n+1} . But when n + 1 {\displaystyle n+1} is not prime, the first factor becomes zero and the formula produces the prime number 2. This formula is not an efficient way to generate prime numbers because evaluating n ! mod ( n + 1 ) {\displaystyle n!{\bmod {(}}n+1)} requires about n 1 {\displaystyle n-1} multiplications and reductions modulo n + 1 {\displaystyle n+1} .

In 1964, Willans gave the formula

p n = 1 + i = 1 2 n ( n j = 1 i ( cos ( j 1 ) ! + 1 j π ) 2 ) 1 / n {\displaystyle p_{n}=1+\sum _{i=1}^{2^{n}}\left\lfloor \left({\frac {n}{\sum _{j=1}^{i}\left\lfloor \left(\cos {\frac {(j-1)!+1}{j}}\pi \right)^{2}\right\rfloor }}\right)^{1/n}\right\rfloor }

for the n {\displaystyle n} th prime number p n {\displaystyle p_{n}} . This formula reduces to p n = 1 + i = 1 2 n [ π ( i ) < n ] {\displaystyle p_{n}=1+\sum _{i=1}^{2^{n}}} ; that is, it tautologically defines p n {\displaystyle p_{n}} as the smallest integer m for which the prime-counting function π ( m ) {\displaystyle \pi (m)} is at least n. This formula is also not efficient. In addition to the appearance of ( j 1 ) ! {\displaystyle (j-1)!} , it computes p n {\displaystyle p_{n}} by adding up p n {\displaystyle p_{n}} copies of 1 {\displaystyle 1} ; for example, p 5 = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + 0 = 11 {\displaystyle p_{5}=1+1+1+1+1+1+1+1+1+1+1+0+0+\dots +0=11} .

The articles What is an Answer? by Herbert Wilf (1982) and Formulas for Primes by Underwood Dudley (1983) have further discussion about the worthlessness of such formulas.

Formula based on a 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. Jones et al. (1976) found an explicit set of 14 Diophantine equations in 26 variables, such that a given number k + 2 is prime if and only if that system has a solution in nonnegative integers:

α 0 = w z + h + j q = 0 {\displaystyle \alpha _{0}=wz+h+j-q=0}
α 1 = ( g k + 2 g + k + 1 ) ( h + j ) + h z = 0 {\displaystyle \alpha _{1}=(gk+2g+k+1)(h+j)+h-z=0}
α 2 = 16 ( k + 1 ) 3 ( k + 2 ) ( n + 1 ) 2 + 1 f 2 = 0 {\displaystyle \alpha _{2}=16(k+1)^{3}(k+2)(n+1)^{2}+1-f^{2}=0}
α 3 = 2 n + p + q + z e = 0 {\displaystyle \alpha _{3}=2n+p+q+z-e=0}
α 4 = e 3 ( e + 2 ) ( a + 1 ) 2 + 1 o 2 = 0 {\displaystyle \alpha _{4}=e^{3}(e+2)(a+1)^{2}+1-o^{2}=0}
α 5 = ( a 2 1 ) y 2 + 1 x 2 = 0 {\displaystyle \alpha _{5}=(a^{2}-1)y^{2}+1-x^{2}=0}
α 6 = 16 r 2 y 4 ( a 2 1 ) + 1 u 2 = 0 {\displaystyle \alpha _{6}=16r^{2}y^{4}(a^{2}-1)+1-u^{2}=0}
α 7 = n + + v y = 0 {\displaystyle \alpha _{7}=n+\ell +v-y=0}
α 8 = ( a 2 1 ) 2 + 1 m 2 = 0 {\displaystyle \alpha _{8}=(a^{2}-1)\ell ^{2}+1-m^{2}=0}
α 9 = a i + k + 1 i = 0 {\displaystyle \alpha _{9}=ai+k+1-\ell -i=0}
α 10 = ( ( a + u 2 ( u 2 a ) ) 2 1 ) ( n + 4 d y ) 2 + 1 ( x + c u ) 2 = 0 {\displaystyle \alpha _{10}=((a+u^{2}(u^{2}-a))^{2}-1)(n+4dy)^{2}+1-(x+cu)^{2}=0}
α 11 = p + ( a n 1 ) + b ( 2 a n + 2 a n 2 2 n 2 ) m = 0 {\displaystyle \alpha _{11}=p+\ell (a-n-1)+b(2an+2a-n^{2}-2n-2)-m=0}
α 12 = q + y ( a p 1 ) + s ( 2 a p + 2 a p 2 2 p 2 ) x = 0 {\displaystyle \alpha _{12}=q+y(a-p-1)+s(2ap+2a-p^{2}-2p-2)-x=0}
α 13 = z + p ( a p ) + t ( 2 a p p 2 1 ) p m = 0 {\displaystyle \alpha _{13}=z+p\ell (a-p)+t(2ap-p^{2}-1)-pm=0}

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

( k + 2 ) ( 1 α 0 2 α 1 2 α 13 2 ) > 0. {\displaystyle (k+2)(1-\alpha _{0}^{2}-\alpha _{1}^{2}-\cdots -\alpha _{13}^{2})>0.}

That is,

( k + 2 ) ( 1 [ w z + h + j q ] 2 [ ( g k + 2 g + k + 1 ) ( h + j ) + h z ] 2 [ 16 ( k + 1 ) 3 ( k + 2 ) ( n + 1 ) 2 + 1 f 2 ] 2 [ 2 n + p + q + z e ] 2 [ e 3 ( e + 2 ) ( a + 1 ) 2 + 1 o 2 ] 2 [ ( a 2 1 ) y 2 + 1 x 2 ] 2 [ 16 r 2 y 4 ( a 2 1 ) + 1 u 2 ] 2 [ n + + v y ] 2 [ ( a 2 1 ) 2 + 1 m 2 ] 2 [ a i + k + 1 i ] 2 [ ( ( a + u 2 ( u 2 a ) ) 2 1 ) ( n + 4 d y ) 2 + 1 ( x + c u ) 2 ] 2 [ p + ( a n 1 ) + b ( 2 a n + 2 a n 2 2 n 2 ) m ] 2 [ q + y ( a p 1 ) + s ( 2 a p + 2 a p 2 2 p 2 ) x ] 2 [ z + p ( a p ) + t ( 2 a p p 2 1 ) p m ] 2 ) > 0 {\displaystyle {\begin{aligned}&(k+2)(1-{}\\&^{2}-{}\\&^{2}-{}\\&^{2}-{}\\&^{2}-{}\\&^{2}-{}\\&^{2}-{}\\&^{2}-{}\\&^{2}-{}\\&^{2}-{}\\&^{2}-{}\\&^{2}-{}\\&^{2}-{}\\&^{2}-{}\\&^{2})\\&>0\end{aligned}}}

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. Hence, there is a prime-generating polynomial inequality as above with only 10 variables. However, its degree is large (in the order of 10). On the other hand, there also exists such a set of equations of degree only 4, but in 58 variables.

Mills' formula

The first such formula known was established by W. H. Mills (1947), who proved that there exists a real number A such that, if

d n = A 3 n {\displaystyle d_{n}=A^{3^{n}}}

then

d n = A 3 n {\displaystyle \left\lfloor d_{n}\right\rfloor =\left\lfloor A^{3^{n}}\right\rfloor }

is a prime number for all positive integers n. If the Riemann hypothesis is true, then the smallest such A has a value of around 1.3063778838630806904686144926... (sequence A051021 in the OEIS) and is known as Mills' constant. This value gives rise to the primes d 1 = 2 {\displaystyle \left\lfloor d_{1}\right\rfloor =2} , d 2 = 11 {\displaystyle \left\lfloor d_{2}\right\rfloor =11} , d 3 = 1361 {\displaystyle \left\lfloor d_{3}\right\rfloor =1361} , ... (sequence A051254 in the OEIS). Very little is known about the constant A (not even whether it is rational). 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 {\displaystyle B} such that

B r n {\displaystyle \lceil B^{r^{n}}\rceil }

is also prime-representing for r > 2.106 {\displaystyle r>2.106\ldots } .

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

2 , 7 , 337 , 38272739 , 56062005704198360319209 , {\displaystyle 2,7,337,38272739,56062005704198360319209,}
176199995814327287356671209104585864397055039072110696028654438846269 , {\displaystyle 176199995814327287356671209104585864397055039072110696028654438846269,\ldots }

Without assuming the Riemann hypothesis, Elsholtz developed several prime-representing functions similar to those of Mills. For example, if A = 1.00536773279814724017 {\displaystyle A=1.00536773279814724017\ldots } , then A 10 10 n {\displaystyle \left\lfloor A^{10^{10n}}\right\rfloor } is prime for all positive integers n {\displaystyle n} . Similarly, if A = 3.8249998073439146171615551375 {\displaystyle A=3.8249998073439146171615551375\ldots } , then A 3 13 n {\displaystyle \left\lfloor A^{3^{13n}}\right\rfloor } is prime for all positive integers n {\displaystyle n} .

Wright's formula

Another 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

g 0 = α {\displaystyle g_{0}=\alpha } and
g n + 1 = 2 g n {\displaystyle g_{n+1}=2^{g_{n}}} for n 0 {\displaystyle n\geq 0} ,

then

g n = 2 2 2 α {\displaystyle \left\lfloor g_{n}\right\rfloor =\left\lfloor 2^{\dots ^{2^{2^{\alpha }}}}\right\rfloor }

is prime for all n 1 {\displaystyle n\geq 1} . Wright gives the first seven decimal places of such a constant: α = 1.9287800 {\displaystyle \alpha =1.9287800} . This value gives rise to the primes g 1 = 2 α = 3 {\displaystyle \left\lfloor g_{1}\right\rfloor =\left\lfloor 2^{\alpha }\right\rfloor =3} , g 2 = 13 {\displaystyle \left\lfloor g_{2}\right\rfloor =13} , and g 3 = 16381 {\displaystyle \left\lfloor g_{3}\right\rfloor =16381} . g 4 {\displaystyle \left\lfloor g_{4}\right\rfloor } is even, and so is not prime. However, with α = 1.9287800 + 8.2843 10 4933 {\displaystyle \alpha =1.9287800+8.2843\cdot 10^{-4933}} , g 1 {\displaystyle \left\lfloor g_{1}\right\rfloor } , g 2 {\displaystyle \left\lfloor g_{2}\right\rfloor } , and g 3 {\displaystyle \left\lfloor g_{3}\right\rfloor } are unchanged, while g 4 {\displaystyle \left\lfloor g_{4}\right\rfloor } is a prime with 4932 digits. This sequence of primes cannot be extended beyond g 4 {\displaystyle \left\lfloor g_{4}\right\rfloor } without knowing more digits of α {\displaystyle \alpha } . Like Mills' formula, and for the same reasons, Wright's formula cannot be used to find primes.

A function that represents all primes

Given the constant f 1 = 2.920050977316 {\displaystyle f_{1}=2.920050977316\ldots } (sequence A249270 in the OEIS), for n 2 {\displaystyle n\geq 2} , define the sequence

f n = f n 1 ( f n 1 f n 1 + 1 ) {\displaystyle f_{n}=\left\lfloor f_{n-1}\right\rfloor (f_{n-1}-\left\lfloor f_{n-1}\right\rfloor +1)} 1

where   {\displaystyle \left\lfloor \ \right\rfloor } is the floor function. Then for n 1 {\displaystyle n\geq 1} , f n {\displaystyle \left\lfloor f_{n}\right\rfloor } equals the n {\displaystyle n} th prime: f 1 = 2 {\displaystyle \left\lfloor f_{1}\right\rfloor =2} , f 2 = 3 {\displaystyle \left\lfloor f_{2}\right\rfloor =3} , f 3 = 5 {\displaystyle \left\lfloor f_{3}\right\rfloor =5} , etc. The initial constant f 1 = 2.920050977316 {\displaystyle f_{1}=2.920050977316} given in the article is precise enough for equation (1) to generate the primes through 37, the 12 {\displaystyle 12} th prime.

The exact value of f 1 {\displaystyle f_{1}} that generates all primes is given by the rapidly-converging series

f 1 = n = 1 p n 1 P n = 2 1 1 + 3 1 2 + 5 1 2 3 + 7 1 2 3 5 + , {\displaystyle f_{1}=\sum _{n=1}^{\infty }{\frac {p_{n}-1}{P_{n}}}={\frac {2-1}{1}}+{\frac {3-1}{2}}+{\frac {5-1}{2\cdot 3}}+{\frac {7-1}{2\cdot 3\cdot 5}}+\cdots ,}

where p n {\displaystyle p_{n}} is the n {\displaystyle n} th prime, and P n {\displaystyle P_{n}} is the product of all primes less than p n {\displaystyle p_{n}} . The more digits of f 1 {\displaystyle f_{1}} 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:

f 1 2.920050977316134712092562917112019. {\displaystyle f_{1}\simeq 2.920050977316134712092562917112019.}

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, f 1 {\displaystyle f_{1}} , which in this case requires a longer list of primes in its calculation.

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

{ a 0 r n } {\displaystyle \left\{a_{0}^{r^{n}}\right\}}

where {   } {\displaystyle \{\ \}} is the function rounding to the nearest integer. For example, with a 0 43.80468771580293481 {\displaystyle a_{0}\approx 43.80468771580293481} and r = 5 / 4 {\displaystyle r=5/4} , this gives 113, 367, 1607, 10177, 102217... (sequence A323176 in the OEIS). Using a 0 = 10 500 + 961 + ε {\displaystyle a_{0}=10^{500}+961+\varepsilon } and r = 1.01 {\displaystyle r=1.01} with ε {\displaystyle \varepsilon } 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.

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 ( mod p ) {\displaystyle P(1)\equiv 0{\pmod {p}}} . But for any integer k, P ( 1 + k p ) 0 ( mod p ) {\displaystyle P(1+kp)\equiv 0{\pmod {p}}} also, so P ( 1 + k p ) {\displaystyle 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 + k p ) = P ( 1 ) = p {\displaystyle 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 ) = n 2 + n + 41 {\displaystyle P(n)=n^{2}+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 {\displaystyle 163=4\cdot 41-1} . There are analogous polynomials for p = 2 , 3 , 5 , 11  and  17 {\displaystyle p=2,3,5,11{\text{ 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 n + n + c is always coprime to S. The integer c may be negative, in which case there is a delay before primes are produced.

It is known, based on Dirichlet's theorem on arithmetic progressions, that linear polynomial functions L ( n ) = a n + b {\displaystyle 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 ) = a n + b {\displaystyle L(n)=an+b} is prime for any n from 0 through k − 1. However, as of 2020, the best known result of such type is for k = 27:

224584605939537911 + 18135696597948930 n {\displaystyle 224584605939537911+18135696597948930n}

is prime for all n from 0 through 26. 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.

Possible formula using a recurrence relation

Another prime generator is defined by the recurrence relation

a n = a n 1 + gcd ( n , a n 1 ) , a 1 = 7 , {\displaystyle a_{n}=a_{n-1}+\gcd(n,a_{n-1}),\quad a_{1}=7,}

where gcd(x, y) denotes the greatest common divisor of x and y. The sequence of differences an+1an 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, ... (sequence A132199 in the OEIS). 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 always odd and so never equal to 2. 587 is the smallest prime (other than 2) not appearing in the first 10,000 outcomes that are different from 1. Nevertheless, in the same paper it was conjectured to contain all odd primes, even though it is rather inefficient.

Note that there is a trivial program that enumerates all and only the prime numbers, as well as more efficient ones, so such recurrence relations are more a matter of curiosity than of any practical use.

See also

References

  1. Mackinnon, Nick (June 1987), "Prime number formulae", The Mathematical Gazette, 71 (456): 113–114, doi:10.2307/3616496, JSTOR 3616496, S2CID 171537609.
  2. Willans, C. P. (December 1964), "On formulae for the n {\displaystyle n} th prime number", The Mathematical Gazette, 48 (366): 413–415, doi:10.2307/3611701, JSTOR 3611701, S2CID 126149459.
  3. Neill, T. B. M.; Singer, M. (October 1965), "To the Editor, The Mathematical Gazette", The Mathematical Gazette, 49 (369): 303–303, doi:10.2307/3612863, JSTOR 3612863
  4. Goodstein, R. L.; Wormell, C. P. (February 1967), "Formulae For Primes", The Mathematical Gazette, 51 (375): 35–38, doi:10.2307/3613607, JSTOR 3613607
  5. Wilf, Herbert S. (1982), "What is an answer?", The American Mathematical Monthly, 89 (5): 289–292, doi:10.2307/2321713, JSTOR 2321713, MR 0653502
  6. Dudley, Underwood (1983), "Formulas for primes", Mathematics Magazine, 56 (1): 17–22, doi:10.2307/2690261, JSTOR 2690261, MR 0692169
  7. Jones, James P.; Sato, Daihachiro; Wada, Hideo; Wiens, Douglas (1976), "Diophantine representation of the set of prime numbers", American Mathematical Monthly, 83 (6), Mathematical Association of America: 449–464, doi:10.2307/2318339, JSTOR 2318339, archived from the original on 2012-02-24.
  8. Matiyasevich, Yuri V. (1999), "Formulas for Prime Numbers", in Tabachnikov, Serge (ed.), Kvant Selecta: Algebra and Analysis, vol. II, American Mathematical Society, pp. 13–24, ISBN 978-0-8218-1915-9.
  9. Jones, James P. (1982), "Universal diophantine equation", Journal of Symbolic Logic, 47 (3): 549–571, doi:10.2307/2273588, JSTOR 2273588, S2CID 11148823.
  10. Mills, W. H. (1947), "A prime-representing function" (PDF), Bulletin of the American Mathematical Society, 53 (6): 604, doi:10.1090/S0002-9904-1947-08849-2.
  11. Caldwell, Chris K.; Cheng, Yuanyou (2005), "Determining Mills' Constant and a Note on Honaker's Problem", Journal of Integer Sequences, 8, Article 05.4.1.
  12. Tóth, László (2017), "A Variation on Mills-Like Prime-Representing Functions" (PDF), Journal of Integer Sequences, 20 (17.9.8), arXiv:1801.08014.
  13. Elsholtz, Christian (2020), "Unconditional Prime-Representing Functions, Following Mills", American Mathematical Monthly, 127 (7), Washington, DC: Mathematical Association of America: 639–642, arXiv:2004.01285, doi:10.1080/00029890.2020.1751560, S2CID 214795216
  14. E. M. Wright (1951), "A prime-representing function", American Mathematical Monthly, 58 (9): 616–618, doi:10.2307/2306356, JSTOR 2306356
  15. Baillie, Robert (5 June 2017), "Wright's Fourth Prime", arXiv:1705.09741v3
  16. Fridman, Dylan; Garbulsky, Juli; Glecer, Bruno; Grime, James; Tron Florentin, Massi (2019), "A Prime-Representing Constant", American Mathematical Monthly, 126 (1), Washington, DC: Mathematical Association of America: 70–73, arXiv:2010.15882, doi:10.1080/00029890.2019.1530554, S2CID 127727922
  17. Steckles, Katie (January 26, 2019), "Mathematician's record-beating formula can generate 50 prime numbers", New Scientist
  18. Simon Plouffe (2019), "A set of formulas for primes", arXiv:1901.01849 As of January 2019, the number he gives in the appendix for the 50th number generated is actually the 48th.
  19. PrimeGrid's AP27 Search, Official announcement, from PrimeGrid. The AP27 is listed in "Jens Kruse Andersen's Primes in Arithmetic Progression Records page".
  20. Rowland, Eric S. (2008), "A Natural Prime-Generating Recurrence", Journal of Integer Sequences, 11 (2): 08.2.8, arXiv:0710.3217, Bibcode:2008JIntS..11...28R.

Further reading

  • 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, JSTOR 2690354.
  • 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–52 errata

External links

Prime number classes
By formula
By integer sequence
By property
Base-dependent
Patterns
k-tuples
By size
  • Mega (1,000,000+ digits)
  • Largest known
  • Complex numbers
    Composite numbers
    Related topics
    First 60 primes
    List of prime numbers
    Category: