Rearranging the alternating harmonic series

The alternating harmonic series is known to converge, i.e.:

$$\sum_{n=1}^{\infty} \frac{(-1)^{n+1}}{n} = 1-\frac{1}{2}+\frac{1}{3} - \frac{1}{4} + \cdots$$

converges. The convergence is conditional, in the sense that

$$\sum_{n=1}^{\infty} \frac{(-1)^{n+1}}{n} \: \text{ converges yet } \: \sum_{n=1}^{\infty} \left|\frac{(-1)^{n+1}}{n}\right| \text{ diverges}.$$

This type of convergence is rather fragile, in that, we can rearrange the terms and change the sum. Very. odd - it seems that infinite series violate commutativity!

It's not actually too hard to prove this fact for the alternating harmonic series. Here's how:

First, let's group the terms in somewhat unusal fashion; we'll group the first three terms and then we'll group by twos after that:

$$\left(1-\frac{1}{2}+\frac{1}{3}\right) + \left(- \frac{1}{4} + \frac{1}{5}\right) + \left(- \frac{1}{6} + \frac{1}{7}\right)\cdots + \left(- \frac{1}{2n} + \frac{1}{2n+1}\right) \cdots$$

Note that the first term is $5/6$, i.e.:

$$1-\frac{1}{2}+\frac{1}{3} = \frac{5}{6}.$$

Every term after that is easily seen to be negative, since the negative term is larger than the positive. Thus, we certainly have:

$$\sum_{n=1}^{\infty} \frac{(-1)^{n+1}}{n} < \frac{5}{6}.$$

Now, let's rearrange the series as follows:

$$\left(1+\frac{1}{3} - \frac{1}{2}\right) + \left(\frac{1}{5}+\frac{1}{7} - \frac{1}{4}\right) + \left(\frac{1}{9}+\frac{1}{11} - \frac{1}{6}\right) + \cdots + \left(\frac{1}{4n-3}+\frac{1}{4n-1} - \frac{1}{2n}\right)+\cdots$$

The strategy for constructing this rearrangement is to take two terms with odd denominator and then one term with even denominator. The resulting general term might seem strange but it's pretty easy to check that it works for $n=1,2,3$.

Importantly, we can combine those fractions in the general term as follows:

$$\frac{1}{4n-3}+\frac{1}{4n-1} - \frac{1}{2n} = \frac{8 n-3}{2 n (4 n-3) (4 n-1)}.$$

Note that this term is always positive. Now, this rearranged series starts

$$1 + \frac{1}{3} - \frac{1}{2} = \frac{5}{6},$$

which are the same first three terms of the original series; the order is different but the sum is the same, namely $5/6$. The subsequent grouped terms in the rearranged series are always postive, though. Thus, the sum of the rearranged series is larger than $5/6$!

Exact values with computer algebra

Once we learn a bit about power series, we'll be able to understand why

$$\sum_{n=1}^{\infty} \frac{(-1)^{n+1}}{n} = \ln(2).$$

For the time being, though, we can demonstrate this with a little computer algebra. I'm typing this up, in fact, in a Jupyter notebook with a SageMath kernel. I mean, we only use the coolest stuff here!

Her's the computation with SageMath:

In [1]:
n = var('n')
pretty_print(sum((-1)**(n+1)/n, n,1,oo))
\[\newcommand{\Bold}[1]{\mathbf{#1}}\log\left(2\right)\]

We can do the same thing with the rearranged series:

In [2]:
pretty_print(sum((8*n-3)/(32*n**3 - 32*n**2 + 6*n), n,1,oo))
\[\newcommand{\Bold}[1]{\mathbf{#1}}\frac{3}{2} \, \log\left(2\right)\]

It's pretty easy to check that these results compare with $5/6$ as claimed:

In [3]:
[log(2.0), 5.0/6.0, 3*log(2.0)/2]
Out[3]:
[0.693147180559945, 0.833333333333333, 1.03972077083992]

ChatGPT from OpenAI

Here's a fun fact: OpenAI's famous ChatGPT gets the wrong result for the rearranged series

Screen%20Shot%202024-04-10%20at%206.29.17%20AM.png

Here's the shared link, by the way.

What's the problem?

ChatGPT get's the wrong result because it sends these kinds of computational questions to a computer algebra package called SymPy. You can even find the exact code that it uses in the shared link.

SageMath also inerfaces SymPy, so we can examine this all right here:

In [4]:
from sympy import symbols, summation, oo

n = symbols('n')
expr = 1/(4*n - 3) + 1/(4*n - 1) - 1/(2*n)
sum_infinity = summation(expr, (n, 1, oo))

sum_infinity
Out[4]:
$\displaystyle \frac{\log{\left(1 - e^{i \pi} \right)}}{2}$