# The Harmonic series

Up a level : Calculus and Analysis
Previous page : Power Series
Next page : Euler's identity

The harmonic series, up to some number n, is defined as

${H_n} = \sum\limits_{i = 1}^n {\frac{1}{n}} = 1 + \frac{1}{2} + \frac{1}{3} + ... + \frac{1}{n}$

To start with there will just be some Harmonic series calculators here, the third one being the fastest – and it is the one you should use if you are just looking for a result.

We also have a fairly fast variant using as many threads as are available, calculating blocks of terms in parallel. This variant quite fast, but with a limited accuracy.  We have for example that 272400600 terms will give you an answer slightly larger than to 20. The sum we get is about 20.00000000161681. The sum might actually vary slightly dependent on the order the treads are running. This due to accumulated rounding errors, and how they might add up in different order. The second variant will instead give the answer 20.000 00000 16174 42189 55814 53329 72303 08878 06676 where all shown digits are correct. This variant uses a trick similar to the one described on this page to calculate decimal numbers using large integers. I have basically re-scaled the numbers so that a large integer, 1060 in this case, will be the new 1.

The first program takes about 1 s on my current laptop to do the calculations, the second algorithm takes about 90 s for the same thing.  Interestingly my phone is about twice as fast….

The inverse is to find how many terms you need to reach, or pass, a given target sum. I.e., if you enter 20 it will give you 272400600.

The third one needs a bit of explanation, so I will dedicate a page on its own for it.

Up a level : Calculus and Analysis
Previous page : Power Series