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$!
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:
n = var('n')
pretty_print(sum((-1)**(n+1)/n, n,1,oo))
We can do the same thing with the rearranged series:
pretty_print(sum((8*n-3)/(32*n**3 - 32*n**2 + 6*n), n,1,oo))
It's pretty easy to check that these results compare with $5/6$ as claimed:
[log(2.0), 5.0/6.0, 3*log(2.0)/2]
Here's a fun fact: OpenAI's famous ChatGPT gets the wrong result for the rearranged series
Here's the shared link, by the way.
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:
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