3
$\begingroup$

There is an exact $n$th prime number formula from mathworld

A double sum for the nth prime pn is $$p_n=1+\sum_{k=1}^{2(\lfloor n\ln n\rfloor+1)}\Biggl[1-\Biggl\lfloor\frac{\sum_{j=2}^k 1+\lfloor s(j)\rfloor}n\Biggr\rfloor\Biggr],\tag{13}$$ where $$s(j)\equiv-\frac{\sum_{s=1}^j \bigl(\bigl\lfloor\frac js\bigr\rfloor-\bigl\lfloor\frac{j-1}s\bigr\rfloor\bigr)-2}j\tag{14}$$

I tried to check it numerically but there is no correct answer :

s[j_] := -(Sum[(Floor[j/s] - Floor[(j - 1)/s]) - 2, {s, 1, j}]/j)

p[n_] := 1 + Sum[1 - Floor[Sum[1 + Floor[s[j]], {j, 2, k}]/n], {k, 1, 
2*(Floor[n Log[n]] + 1)}]


p[30]

-1106

$\endgroup$
5
  • $\begingroup$ Note that the website cites this: gallup.unm.edu/~smarandache/articulo/artic.htm $\endgroup$
    – Feyre
    Commented Dec 13, 2016 at 11:12
  • $\begingroup$ Have you seen this? $\endgroup$ Commented Dec 13, 2016 at 11:15
  • $\begingroup$ @J.M. Are you saying mathworld (and UNM) simply mistate the formula? $\endgroup$
    – Feyre
    Commented Dec 13, 2016 at 11:18
  • 2
    $\begingroup$ Looks like it. Thus: s[j_] := 2 (1 + Sum[Floor[(j - 1)/s] - Floor[j/s], {s, 1, Sqrt[j]}])/j $\endgroup$ Commented Dec 13, 2016 at 11:56
  • $\begingroup$ @J.M. hence there is a mistake in mathword article $\endgroup$
    – vito
    Commented Dec 13, 2016 at 12:16

1 Answer 1

2
$\begingroup$

J. M.'s correction:

s[j_] := 2 (1 + Sum[⌊(j - 1)/s⌋ - ⌊j/s⌋, {s, 1, Sqrt[j]}])/j

p[n_] := 1 + Sum[1 - ⌊Sum[1 + ⌊s[j]⌋, {j, 2, k}]/n⌋, {k, 1, 2*(⌊n Log[n]⌋ + 1)}]

p[30]       (* 113 *)

Prime[30]   (* 113 *)
$\endgroup$
1
  • 1
    $\begingroup$ I'd use Quotient[] instead of Floor[] + division myself (just like in the article I linked to). Nevertheless, it should be emphasized that this is of course an expensive way to generate primes. $\endgroup$ Commented Dec 13, 2016 at 12:17

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.