TOPICS
Search

Prime Formulas


There exist a variety of formulas for either producing the nth prime as a function of n or taking on only prime values. However, all such formulas require either extremely accurate knowledge of some unknown constant, or effectively require knowledge of the primes ahead of time in order to use the formula (Dudley 1969; Ribenboim 1996, p. 186). There also exist simple prime-generating polynomials that generate only primes for the first (possibly large) number of integer values.

There are also many beautiful formulas involving prime sums and prime products that can be done in closed form.

Considering examples of formulas that produce only prime numbers (although not necessarily the complete set of prime numbers P), there exists a constant theta=1.3063... (OEIS A051021) known as Mills' constant such that

 f(n)=|_theta^(3^n)_|,
(1)

where |_x_| is the floor function, is prime for all n>=1 (Ribenboim 1996, p. 186). The first few values of f(n) are 2, 11, 1361, 2521008887, ... (OEIS A051254). It is not known if theta is irrational. There also exists a constant omega approx 1.9287800 (OEIS A086238) such that

 g(n)=|_2omegan_|
(2)

(Wright 1951; Ribenboim 1996, p. 186) is prime for every n>=1. The first few values of g(n) are 3, 13, 16381, ... (OEIS A016104). In the case of both f(n) and g(n), the numbers at n=4 grow so rapidly that an extremely precise value of theta or omega is needed in order to obtain the correct value, and values for n>=5 are effectively incomputable.

Explicit formulas exist for the nth prime both as a function of n and in terms of the primes 2, ..., p_(n-1) (Hardy and Wright 1979, pp. 5-6, 344-345, and 414; Guy 1994, pp. 36-41), a number of which are given below. However, it should again be emphasized that these formulas are extremely inefficient, and in many (if not all) cases, simply performing an efficient sieving would yield the primes much more quickly and efficiently.

A prime-generating formula sometimes known as Willans' formula can be constructed as follows. Let

F(j)=|_cos^2[pi((j-1)!+1)/j]_|
(3)
={1 for j=1 or j prime; 0 otherwise
(4)

for j>1 an integer, where |_x_| is again the floor function. This formula is a consequence of Wilson's theorem and conceals the prime numbers j as those for which F(j)=1, i.e., the values of F(j) are 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, ... (OEIS A080339). Then

 pi(x)=-1+sum_(k=1)^xF(k)
(5)

and

p_n=1+sum_(m=1)^(2^n)|_|_n/(sum_(j=1)^(m)F(j))_|^(1/n)_|
(6)
=1+sum_(m=1)^(2^n)|_|_n/(1+pi(m))_|^(1/n)_|,
(7)

where pi(m) is the prime counting function (Willans 1964; Havil 2003, pp. 168-169).

Gandhi gave the formula in which p_(n+1) is the unique integer such that

 1<2^(p_(n+1))(sum_(d|p_n#)(mu(d))/(2^d-1)-1/2)<2,
(8)

where p_n# is the primorial function (Gandhi 1971, Eynden 1972, Golomb 1974) and mu(n) is the Möbius function. It is also true that

 p_(n+1)=1+p_n+F(p_n+1)+F(p_n+1)F(p_n+2)+product_(j=1)^pF(p_n+j)
(9)

(Ribenboim 1996, pp. 180-182). Note that the number of terms in the summation to obtain the nth prime is 2^n, so these formulas turn out not to be practical in the study of primes.

Hardy and Wright (1979, p. 414) give the formula

 p_n=1+sum_(j=1)^(2^n)f(n,pi(j)),
(10)

for n>3, where

 f(x,y)={0   for x=y; 1/2[1+(x-y)/(|x-y|)]   for x!=y
(11)

and an "elementary" formula for the prime counting function is given by

 pi(n)=-1+sum_(j=3)^n[(j-2)!-j|_((j-2)!)/j_|]
(12)

(correcting a sign error), where |_x_| is the floor function.

A double sum for the nth prime p_n is

 p_n=1+sum_(k=1)^(2(|_nlnn_|+1))[1-|_(sum_(j=2)^(k)1+|_s(j)_|)/n_|],
(13)

where

 s(j)=-(sum_(s=1)^(j)(|_j/s_|-|_(j-1)/s_|)-2)/j
(14)

(Ruiz 2000).

PrimeFormulaCipolla

An asymptotic formula for p_n is given by

 p_n∼n(lnn+lnlnn-1+(lnlnn-2)/(lnn)-(ln^2(lnn)-6lnlnn+11)/(2ln^2n)+...)
(15)

(Cipolla 1902). This asymptotic expansion is the inverse of the logarithmic integral Li(x) obtained by series reversion, where the inversion of Li(x) gives p_n because the prime number theorem says that Li(x)∼pi(x), where pi(x) is the prime counting function and the inverse of pi(x) is p_n in the sense that pi(p_n)=n. However, the formula oscillates a great deal as illustrated above, where p_n-p^^_n is the difference between the actual nth prime and that given by the Cipolla formula. Interestingly, truncating at n(lnn+lnlnn-1) gives the refined form of Rosser's theorem, which is a strict inequality on p_n. Salvy (1994) deals with more general cases.

PrimeFormulaBredihin

B. M. Bredihin proved that

 f(x,y)=x^2+y^2+1
(16)

takes prime values for infinitely many integral pairs (x,y) (Honsberger 1976, p. 30). For example, f(1,1)=3, f(1,3)=11, f(1,9)=83, and so on. The primes of this form are 3, 11, 19, 41, 53, 59, 73, 83, 101, 107, 131, 137, 149, 163, ... (OEIS A079544; Mitrinović and Sándor 1995, p. 11). The values of x and y for which f(x,y) is prime are plotted above, showing some interesting patterns.

It is in general not difficult to artificially construct formulas that always generate prime numbers. For example, consider the formula

 f(x,y)=1/2(y-1)[|B^2(x,y)-1|-(B^2(x,y)-1)]+2,
(17)

where

 B(x,y)=x(y+1)-(y!+1),
(18)

y! is the factorial, and x and y are positive integers (Honsberger 1976, p. 33). This will always have B(x,y)^2>1 and hence yield the value 2 unless x=[(p-1)!+1]/p and y=p-1, in which case it simplifies to

 f(((p-1)!+1)/p,p-1)=p
(19)

The formula therefore generates odd primes exactly once each (Honsberger 1976, p. 33) at the values for which the Wilson quotient x=[(p-1)!+1]/p is an integer, i.e., 1, 1, 5, 103, 329891, 36846277, 1230752346353, ... (OEIS A007619).

The FRACTRAN game (Guy 1983, Conway and Guy 1996, p. 147) provides an unexpected means of generating the prime numbers based on 14 fractions, but it is actually just a concealed version of a sieve.


See also

FRACTRAN, Mills' Constant, Prime Counting Function, Prime Number, Prime Products, Prime Sums, Rosser's Theorem, Sieve, Willans' Formula

Related Wolfram sites

http://functions.wolfram.com/NumberTheoryFunctions/Prime/

Explore with Wolfram|Alpha

References

Cipolla, M. ""La determinazione assintotica dell'n^(imo) numero primo." Napoli Rend. 3, 132-166, 1902.Conway, J. H. and Guy, R. K. The Book of Numbers. New York: Springer-Verlag, pp. 130 and 147, 1996.Dudley, U. "History of Formula for Primes." Amer. Math. Monthly 76, 23-28, 1969.Dusart, P. "The k^(th) Prime is Greater than k(lnk+lnlnk-1) for k>=2." Math. Comput. 68, 411-415, 1999.Eynden, C. V. "A Proof of Gandhi's Formula for the nth Prime." Amer. Math. Monthly 79, 625, 1972.Finch, S. R. "Hardy-Littlewood Constants." §2.1 in Mathematical Constants. Cambridge, England: Cambridge University Press, pp. 84-94, 2003.Gandhi, J. M. "Formulae for the Nth Prime." Proc. Washington State University Conferences on Number Theory. pp. 96-107, 1971.Gardner, M. "Patterns and Primes." Ch. 9 in The Sixth Book of Mathematical Games from Scientific American. Chicago, IL: University of Chicago Press, pp. 79-90, 1984.Golomb, S. W. "A Direct Interpretation of Gandhi's Formula." Amer. Math. Monthly 81, 752-754, 1974.Guy, R. K. "Conway's Prime Producing Machine." Math. Mag. 56, 26-33, 1983.Guy, R. K. "Prime Numbers," "Formulas for Primes," and "Products Taken over Primes." Ch. A, §A17, and §B48 in Unsolved Problems in Number Theory, 2nd ed. New York: Springer-Verlag, pp. 3-43, 36-41, and 102-103, 1994.Hardy, G. H. and Wright, E. M. "Prime Numbers" and "The Sequence of Primes." §1.2 and 1.4 in An Introduction to the Theory of Numbers, 5th ed. Oxford, England: Clarendon Press, pp. 1-4, 5-6, 344-345, and 414, 1979.Havil, J. Gamma: Exploring Euler's Constant. Princeton, NJ: Princeton University Press, 2003.Honsberger, R. Mathematical Gems II. Washington, DC: Math. Assoc. Amer., 1976.Mills, W. H. "A Prime-Representing Function." Bull. Amer. Math. Soc. 53, 604, 1947.Mitrinović, D. S. and Sándor, J. Handbook of Number Theory. Dordrecht, Netherlands: Kluwer, 1995.Ribenboim, P. The New Book of Prime Number Records. New York: Springer-Verlag, 1996.Ruiz, S. M. "The General Term of the Prime Number Sequence and the Smarandache Prime Function." Smarandache Notions J. 11, 59-61, 2000.Salvy, B. "Fast Computation of Some Asymptotic Functional Inverses." J. Symb. Comput. 17, 227-236, 1994.Sloane, N. J. A. Sequences A007619/M4023, A016104, A051021, A051254, A079544, A080339, and A086238 in "The On-Line Encyclopedia of Integer Sequences."Willans, C. P. "A Formula for the nth Prime Number." Math. Gaz. 48, 413-415, 1964.Wright, E. M. "A Prime-Representing Function." Amer. Math. Monthly 58, 616-618, 1951.

Referenced on Wolfram|Alpha

Prime Formulas

Cite this as:

Weisstein, Eric W. "Prime Formulas." From MathWorld--A Wolfram Web Resource. https://mathworld.wolfram.com/PrimeFormulas.html

Subject classifications