Skip to content

Instantly share code, notes, and snippets.

@Mr-Bossman
Created March 25, 2024 20:48
Show Gist options
  • Save Mr-Bossman/7e425b3b1f6f12380464ab183fe97aec to your computer and use it in GitHub Desktop.
Save Mr-Bossman/7e425b3b1f6f12380464ab183fe97aec to your computer and use it in GitHub Desktop.
Example of Bailey–Borwein–Plouffe digit extraction formula
# Example of Bailey–Borwein–Plouffe digit extraction formula
extra = 2
def BBP_8k(k,j):
return (8*k+j)
def BBP_mod(n, d):
return (16**n) % d
def BBP_inner(n, j):
total = 0
for k in range(n+extra):
tmp = BBP_8k(k, j)
total += BBP_mod(n-k, tmp) / tmp
return total
def BBP_one(n):
T1 = 4.0 * BBP_inner(n, 1)
T2 = -2.0 * BBP_inner(n, 4)
T3 = -1.0 * BBP_inner(n, 5)
T4 = -1.0 * BBP_inner(n, 6)
return T1 + T2 + T3 + T4
for n in range(200):
p = 4
s = BBP_one(n) % 1
s *= 16
print(hex(int(s))[2:], end=' ')
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment