Pi from String Theory Amplitudes
From the paper by Arnab Priya Saha and Aninda Sinha. A new series for
Where
This can be implemented in Python as follows:
import mpmath as mp
def mp_calculate_pi(lambda_val, iters):
mp.dps = 100
pi = mp.mpf(4)
n = 1
prev_pi = 0
factorial = mp.mpf(n)
for i in range(iters):
term1 = 1.0 / factorial
term2 = 1.0 / (n + lambda_val) - 4 / (2 * n + 1)
term3 = ((2 * n + 1) ** 2) / (4 * (n + lambda_val)) - n
pochhammer = 1
for i in range(n - 1):
pochhammer *= term3 + i
prev_pi = pi
pi += term1 * term2 * pochhammer
# print to 30 decimal places using mpmath
approx = mp.nstr(pi, 100)
# Compare to mp.pi to calcualte the delta
delta = abs(pi - mp.pi)
# numbers of digits that pi approximate is correct to
accuracy = round(abs(mp.log(abs(pi - mp.pi), 10)))
# Print a line with the current iteration, pi, delta
print(f'{n} {approx} {delta} {accuracy}')
n += 1
factorial = factorial * n
return pi, n - 1
lambda_val = 42
pi, n = mp_calculate_pi(lambda_val, 30)