3.14159264621354594737567822448909282684326171875
3.1415926535897935600871733186068013310432434082031
3.1415926535897935600871733186068013310432434082031
3.1415926535897935600871733186068013310432434082031
3.1415926535897935600871733186068013310432434082031
What puzzles me is that the long numerical strings above look like Pi,
but all the digits after the 15th decimal place are wrong. This is an
iterative process that should converge quartically, and the figures
above suggest that Pi has converged after the 2nd iteration, given
the chosen precision. But it converged to the wrong number, and I
wonder why.
Here's the code I've been using:
import mpmath as mp
mp.dps = 72
mp.pretty = True
one = mp.mpf('1.0')
two = mp.mpf('2.0')
four = mp.mpf('4.0')
six = mp.mpf('6.0')
m = -one/four
tmp = mp.mpf(0)
val = mp.mpf(0)
sqrt2 = mp.sqrt(two)
y = sqrt2 - one
a = six - four*sqrt2
for k in range(0,12):
tmp = (one - mp.power(y,four))
tmp = tmp**m
y = (tmp - one)/(tmp + one)
a = a*mp.power((one + y),four) - \
y*mp.power(two,(2*k+3))*(one + y + mp.power(y,2))
val = one/a
print(mp.nstr(val,50))
Can you spot any mistake in it? The 'algorithmization' is probably
correct, otherwise the script wouldn't yield Pi correct to fifteen
decimal places. It's something wrong I did with mpmath. But what?
Ubuntu 18.04, Python 3.6.8 and mpmath 1.1.0.
Thanks a lot for any light shed on this matter.
C.G.