16-2 Willans's Formulas

C. P. Willans gives the following formula for the nth prime [Will]:

graphics/16icon13.gif

 

The derivation starts from Wilson's theorem, which states that p is prime or 1 if and only if (p - 1)! -1(mod p). Thus,

graphics/16icon14.gif

 

is an integer for x prime or x = 1 and is fractional for all composite x. Hence

Equation 1

graphics/16icon15.gif

 

Thus, if p(m) denotes [2] the number of primes m,

[2] Our apologies for the two uses of p in close proximity, but it's standard notation and shouldn't cause any difficulty.

Equation 2

graphics/16icon16.gif

 

Observe that p(pn) = n, and furthermore,

graphics/16icon17.gif

 

Therefore, the number of values of m from 1 to for which is p(m) < n is pn - 1. That is,

Equation 3

graphics/16icon18.gif

 

where the summand is a "predicate expression" (0/1-valued).

Because we have a formula for p(m), Equation (3) constitutes a formula for the nth prime as a function of n. But it has two features that might be considered unacceptable: an infinite summation and the use of a "predicate expression," which is not in standard mathematical usage.

It has been proved that for n 1 there is at least one prime between n and 2n. Therefore, the number of primes 2n is at least n梩hat is, p(2n) n. Thus, the predicate p(m) < n is 0 for m 2n, so the upper limit of the summation above can be replaced with 2n.

Willans has a rather clever substitute for the predicate expression. Let

graphics/16icon19.gif

 

Then, if x < y, 1 y/(1 + x) y, so graphics/16icon20.gifFurthermore, if x y, then 0 < y/(1 + x) < 1, so graphics/16icon21.gifApplying the floor function, we have

graphics/16icon22.gif

 

That is, LT(x, y) is the predicate x < y (for x and y in the given ranges).

Substituting, Equation (3) can be written

graphics/16icon23.gif

 

Further substituting Equation (2) for p(m) in terms of F(x), and Equation (1) for F(x), gives the formula shown at the beginning of this section.

Second Formula

Willans then gives another formula:

graphics/16icon24.gif

 

Here, F and p are the functions used in his first formula. Thus, mF(m) = m if m is prime or 1, and 0 otherwise. The third factor in the summand is the predicate p(m) =n. The summand is 0 except for one term, which is the nth prime. For example,

graphics/16icon25.gif

 

Third Formula

Willans goes on to present another formula for the nth prime that does not use any "nonanalytic" [3] functions such as floor and absolute value. He starts by noting that for x = 2, 3, ? the function

[3] This is my terminology, not Willans's.

graphics/16icon26.gif

 

The first part follows from

graphics/16icon27.gif

 

and x divides (x - 1)! + 1, by Wilson's theorem. Thus, the predicate "x is prime," for x 2 is given by

graphics/16icon28.gif

 

From this it follows that

graphics/16icon29.gif

 

This cannot be converted to a formula for pn by the methods used in the first two formulas, because they use the floor function. Instead, Willans suggests the following formula [4] for the predicate x < y, for x, y 1:

[4] We have slightly simplified his formula.

graphics/16icon30.gif

 

Thus, if x < y, e = x(x - 1)?0)(-1)?x - (y - 1)) = 0 so that LT(x, y) = sin(p/2) = 1. If x y, the product does not include 0, so e 1, so that LT(x, y) = sin((p/2) ?(an even number)) = 0.

Finally, as in the first of Willans's formulas,

graphics/16icon31.gif

 

Written out in full, this is the rather formidable

graphics/16icon32.gif

 

Fourth Formula

Willans then gives a formula for pn+1 in terms of pn:

graphics/16icon33.gif

 

where f(x) is the predicate "x is composite," for x 2; that is,

graphics/16icon34.gif

 

Alternatively, one could use f(x) = 1 - H(x), to keep the formula free of floor functions.

As an example of this formula, let pn = 7. Then,

graphics/16icon35.gif