Created
March 25, 2024 20:48
-
-
Save Mr-Bossman/7e425b3b1f6f12380464ab183fe97aec to your computer and use it in GitHub Desktop.
Example of Bailey–Borwein–Plouffe digit extraction formula
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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