Let's define $(p_n)_{n\in \mathbb N}$ the ordered list of prime numbers ($p_0=2$, $p_1=3$, $p_2=5$...).

I am interested in the following sum:

$$S_n:=\sum_{k=1}^n (-1)^kp_k$$

Since the sequence $(S_n)$ is related to the gaps between prime numbers, I would expect it to be quite irregular.

But if we plot $(S_n)_{1\leqslant n\leqslant N}$ for $N\in \{50,10^3,10^5,10^6,10^7\}$, we obtain the following:

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

We can observe a great regularity.

So my questions are:

  • Why is there so much regularity?

  • Can we find the equations of the two lines forming $(S_n)$?

  • Is there a proof that it will continue to be that regular forever?

Any contribution, even partial, will be greatly appreciated.


Thanks to mixedmath and Daniel Fischer, here is more curves:

  • in blue, you have $S_n$;

  • in red, you have $\displaystyle 2^{1/6}\displaystyle \sum (-1)^k k\log k$;

  • in green, you have $\displaystyle \sum (-1)^k k\log k$;

  • in purple, you have $\displaystyle \sum (-1)^k k(\log k+\log\log k)$;

  • in yellow, you have $\displaystyle \sum (-1)^k k(\log k+\log\log k-1)$.

enter image description here

enter image description here

enter image description here

My question seems quite related to this one.

  • $\begingroup$ Did you take $1$ as a prime? It seems you did, because in the first diagram, $S_2<0$. $\endgroup$ – Mastrem Jun 8 '17 at 11:12
  • $\begingroup$ @Mastrem I did not, in the first diagram, $S_1=2>0$, and $S_2=2-3=-1<0$. $\endgroup$ – E. Joseph Jun 8 '17 at 11:49
  • $\begingroup$ Then shouldn't $S_n$ be defined as $S_n:=\sum_{k=1}^{n}(-1)^kp_k$? The way it's currently defined, we have $S_1=0$, as there are no primes lower than or equal to $1$. $\endgroup$ – Mastrem Jun 8 '17 at 12:00
  • 1
    $\begingroup$ for the third question you have to show that $|\sum \limits_{k=1}^n (-1)^k p_k| \approx \frac{p_n}{2}$ $\endgroup$ – Ahmad Jun 8 '17 at 15:25
  • 1
    $\begingroup$ Ah, I hadn't noticed that you'd edited in the additional graphs. Indeed, the extra terms from Dusart's bounds (including the $-1$) look very good. $\endgroup$ – davidlowryduda Jun 8 '17 at 20:52

This is a great question. Unfortunately, this is an incomplete answer. But I thought about this a bit and I noticed something interesting, but which I do not know how to explain.

With $$ S_n = \sum_{k \leq n} (-1)^k p_k,$$ where $p_n$ is the $n$th prime, some patterns are immediately clear. It is obvious that the sequence of $S_n$ alternates in sign for example. But some patterns are not obvious or clear.

By the prime number theorem, we expect that $p_n \approx n \log n$. If we plot $\sum_{k \leq n} (-1)^k k \log k$ against $S_n$ for all primes up to one million, we get

A pretty good, but not great, plot

This is apparently a bit too small, it seems. This sort of makes sense, as deviations from the approximation $p_n \approx n \log n$ compound here.

However, I noticed that $$ 1.12 \sum_{k \leq n} (-1)^k k \log k $$ is actually a very good (experimental) estimate of what's going on, as can be seen in the following plot.

A better fit

Perhaps $1.12$ is an incorrect choice --- it just happened to be a very nearby reasonable seeming number, and it does appear to reflect what's going on. I do not know why, though.

If we conjecture for a moment that $1.12 \sum (-1)^k k \log k$ is a good estimator, then we can write a good asymptotic for this series using partial summation. Namely

$$ \begin{align} \sum_{k \leq n} (-1)^k k \log k &= \left( \sum_{k \leq n} (-1)^k k \right) \log n - \int_1^n \left( \sum_{k \leq t} (-1)^k k \right) \frac{1}{t} dt \\ &= (-1)^n \left \lfloor \frac{n+1}{2} \right \rfloor \log n - \int_1^n (-1)^{\lfloor t \rfloor} \left \lfloor \frac{\lfloor t \rfloor+1}{2} \right \rfloor \frac{1}{t} dt \\ &= (-1)^n \left \lfloor \frac{n+1}{2} \right \rfloor \log n + O \left( \int_1^n \left( \frac{t+1}{2t} + \frac{2}{t} \right) dt\right) \\ &= (-1)^n \left \lfloor \frac{n+1}{2} \right \rfloor \log n + O(n). \end{align}$$

So I conjecture that $$S_n \approx 1.12 (-1)^n \left \lfloor \frac{n+1}{2} \right \rfloor \log n + O(n).$$ For comparison, the size of the alternating sum of the first 1001 primes is $3806$, where this estimate gives about $3876.6$. For $10001$, the actual is $52726$, compared to the estimated $51588.7$. These are both close, although apparently not super accurate.

It may be possible to describe the actual behavior of $S_n$ a bit more by using secondary terms in the prime number theorem, but I was not successful in my back-of-the-envelope computations. Nor do I know how to explain the $1.12$ that appears in this answer (or how to determine if it is $1.12$ as opposed to, say, $1.15$). Perhaps someone else will see how to fill in these gaps.

(Edited in after Daniel Fischer's comment)

Here are updated images, including plots of $\sum (-1)^n n (\log n + \log \log n)$.

now including a third line

As we can see, $\sum (-1)^n n (\log n + \log \log n)$ grows in magnitude just a little bit more quickly. Focusing a bit on just the upper half, we get

this actually looks pretty much the same

  • $\begingroup$ Thank you for this great work! For the minus sign, I defined $p_0=2$ so I would avoid the first negative sign, but this is not really important. I found it strange how $\sqrt 5$ pop here. I wish someone will see how to fill these gaps! Thanks again for this work, it gave me a lot to think about. $\endgroup$ – E. Joseph Jun 8 '17 at 16:24
  • $\begingroup$ I have tried to replicate your results for the last $20$ minutes, but it can't seem to work. It seems that $\sqrt 5\sum (-1)^k k \log k$ is way superior to $S_n$. I don't understand why we obtain such different results. $\endgroup$ – E. Joseph Jun 8 '17 at 16:52
  • $\begingroup$ @E.Joseph Ah, you are correct. I made a (very silly) mistake in my code. I will change it and update accordingly. $\endgroup$ – davidlowryduda Jun 8 '17 at 17:22
  • 1
    $\begingroup$ It would be interesting to see the plot of $\sum (-1)^k k(\log k + \log \log k)$ in there too. $\endgroup$ – Daniel Fischer Jun 8 '17 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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