Last active
November 5, 2022 20:33
-
-
Save mo271/5224cd4e514a1b76ca6eeea5d7ca2b3d to your computer and use it in GitHub Desktop.
This file contains 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
from codetiming import Timer | |
from decimal import Decimal, getcontext | |
@Timer() | |
def BBPzeta2(n: int) -> Decimal: | |
s = Decimal(0) | |
f = Decimal(1) | |
# TODO: figure out exactly how fast this converges, | |
# but I think math.log(10, 64) should be the right factor here | |
for k in range(int(n*0.5536546824812272) + 1): | |
sixk = Decimal(6)*Decimal(k) | |
s += f*( Decimal(16)/ (sixk + 1)**2 | |
- Decimal(24)/ (sixk + 2)**2 | |
- Decimal(8) / (sixk + 3)**2 | |
- Decimal(6) / (sixk + 4)**2 | |
+ Decimal(1) / (sixk + 5)**2) | |
f *= Decimal(1)/Decimal(64) | |
return Decimal(3)/Decimal(16)*s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment