Alternating Harmonic Series

The alternating harmonic series is defined as

$$A_n = \sum_{k = 0}^n [-1]^k \frac{1}{k} \,.$$

If infinite reordering is allowed, the limiting value for $n \to \infty$ can be arbitrarily chosen. This can be shown with the following program. It will reorder the terms of this series in a way that the series converges to the limiting value that you specify beforehand. This is no mathematical proof, just a neat illustration.

Here I chose the limiting value 0.3. You can see which terms it adds and subtracts, what the current value and error are:

$ ./grenzwert 
Gewünschter Grenzwert: 0.3
+ 1/   1, aktuell: +1.000000, Fehler: +0.700000
- 1/   2, aktuell: +0.500000, Fehler: +0.200000
- 1/   4, aktuell: +0.250000, Fehler: -0.050000
+ 1/   3, aktuell: +0.583333, Fehler: +0.283333
- 1/   6, aktuell: +0.416667, Fehler: +0.116667
- 1/   8, aktuell: +0.291667, Fehler: -0.008333
+ 1/   5, aktuell: +0.491667, Fehler: +0.191667
- 1/  10, aktuell: +0.391667, Fehler: +0.091667
- 1/  12, aktuell: +0.308333, Fehler: +0.008333
- 1/  14, aktuell: +0.236905, Fehler: -0.063095
+ 1/   7, aktuell: +0.379762, Fehler: +0.079762
- 1/  16, aktuell: +0.317262, Fehler: +0.017262
- 1/  18, aktuell: +0.261706, Fehler: -0.038294
+ 1/   9, aktuell: +0.372817, Fehler: +0.072817
- 1/  20, aktuell: +0.322817, Fehler: +0.022817
- 1/  22, aktuell: +0.277363, Fehler: -0.022637
+ 1/  11, aktuell: +0.368272, Fehler: +0.068272
- 1/  24, aktuell: +0.326605, Fehler: +0.026605
- 1/  26, aktuell: +0.288144, Fehler: -0.011856
+ 1/  13, aktuell: +0.365067, Fehler: +0.065067
- 1/  28, aktuell: +0.329353, Fehler: +0.029353
- 1/  30, aktuell: +0.296019, Fehler: -0.003981