Mark44
Mentor
- 38,048
- 10,543
Both points made by @pbuk are very important.pbuk said:or eqivalently work with exact fractions: ## \frac{1}{2} +\frac{1}{3} + \frac{1}{7} + \frac{1}{41} - \frac{1}{1722} = \frac{861 + 574 + 246 + 42 - 1}{1722} = 1 = \frac{k}{6 + 1}, k = 7 ##
As an example, I wrote a Python program to calculate 1 + 1/2 + 1/3 + ... + 1/n. This isn't the same as the calculation done in this thread, but it shows the effects of error accumulation for different calculation algorithms.
Ex. 1 - Calculate 1 + 1/2 + 1/3 + ... + 1/15
By writing the above as a single fraction over a common denominator of 15! the result was 3.3182289932289932
By brute force addition of the fractions the result was 3.3182289932289937
The difference between the two results is about ##4.5 \times 10^{-16}##.
Ex. 2 - Calculate 1 + 1/2 + 1/3 + ... + 1/20
Same results from both methods
Ex. 3 - Calculate 1 + 1/2 + 1/3 + ... + 1/50
By writing the above as a single fraction over a common denominator of 30! the result was 4.499205338329425
My brute force addition of the fractions the result was 4.499205338329423
The difference between these two results is about ##1.8 \times 10^{-15}##