The following is a formula for the $n$-th prime number ($[\,]$ represents the floor function). Who was the first person to discover it?

$$\newcommand{\lowerbrack}[2]{% \raise{-#1}{\left[\raise{#1}{#2}\right]}} p(n) = 1 + \sum_{k=1}^{2^n} \lowerbrack{9pt}{ \sqrt[n]{\frac{n}{\sum\limits_{i=1}^k \left[ \cos^2 \frac{(i-1)! + 1}{i} \pi \right]}} } $$

The value of this formula: people have been exploring the general term of the prime number sequence, and this is an answer to it.

  • 3
    $\begingroup$ Did you a basic google search? The first search I tried, a phrase search for "formulas for primes", leads to a lot of places to begin looking. You'll want to focus especially on journal papers cited in connection with this specific formula and survey papers of such formulas in general, and for these this google scholar search will also be helpful. Also try varying the phrase to things like "prime formulas", "prime number formulas", etc. $\endgroup$ Jul 11, 2021 at 15:17

1 Answer 1


The formula is derived in Willans, On Formulae for the nth Prime Number (1964) (Mathematical Gazette vol. 48, no. 366, pp. 413-415), who references Dickson's History of the Theory of Numbers, ch. XVIII "for references to other formulae of this nature". He does not quite mean explicit formulas for $p_n$, but rather explicit formulas for functions that take different types of values on primes and non-primes (and can be adapted to the task by simple manipulations that Willans sketches). Explicit formulas of a somewhat different nature were published earlier by Mills A prime-representing function (1947) and Wright A Prime-Representing Function (1951).

Dickson gives a couple of examples, including Pocklington's 1911 example based on Wilson's theorem that seems to be Willans's inspiration. Later variations on the theme are reviewed in Dudley's Formulas for Primes (1982), who remarks:"Although Wilson's Theorem has proved to be notoriously unuseful in finding primes, this has not stopped the production of formulas in which it is essential". Interestingly, Willans shared the sentiment, and already felt the need to justify the exercise:

"While the formulae in this article are unsuitable for application to problems in prime number theory, they at least provide definite answers to the questions (see e.g. Hardy and Wright, An Introduction to the Theory of Numbers, § 1.5):
Is there a formula for the nth prime number?
Is there a formula for a prime, given the preceding prime?

Connes, the Fields medalist best known for developing noncommutative differential geometry, wrote a recent follow-up Around Wilson's theorem (2018) that quotes Willans's related formula for the prime number function. Rowland's A natural prime-generating recurrence (2017) quotes Willans's formula from the OP noting that it and its relatives are "generally infeasible to compute in practice".

  • $\begingroup$ I was surprised that the formula was so new. $\endgroup$
    – user776490
    Jul 13, 2021 at 8:56
  • 3
    $\begingroup$ @Conifold, It is a pity you didn't quote Dudley's conclusion in "Formulas for Primes": "... formulas for formulas' sake do not advance the mathematical enterprise". Formulas should be useful. If not they should be astounding, elegant, enlightening, simple, or have some redeeming value". I am curious to know whether you think Willan's formula has any of these values? $\endgroup$
    – Ng Ph
    Jul 14, 2021 at 9:31
  • $\begingroup$ @NgPh I do not know if it can astound or enlighten somebody, or suggest something useful to them, maybe. Willans got the formula as a side effect of reflections on relationships between different types of formulas in Dickson that Dudley and later Connes reused. Sometimes insights come from unexpected places and in small increments, so I am content to pass on the information. $\endgroup$
    – Conifold
    Jul 15, 2021 at 0:33
  • 1
    $\begingroup$ @NgPh That sentence is too cumbersome, sorry, the intended object of "reused" was "reflections" rather than "formula" :) $\endgroup$
    – Conifold
    Jul 15, 2021 at 8:28
  • 1
    $\begingroup$ @NgPh Syntax and notation is a product of our culture and history. And below that big layer of smoke lies the fact that we can pick any notation we like, any syntax we like. We can define any operator we like. And we can make formulas shorter and longer depending on those selections. - It just happens that our historically grown syntax has no operators suitable for defining primes efficiently. And for me, that's exactly what this formula demonstrates. It is composed of re-usable parts that could have been operators. He's just defining them inline, to adhere to our very selective rules. $\endgroup$
    – bvdb
    Oct 9, 2022 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.