Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Calculates Riemann's Zeta(3)
- # which is also Apery's constant
- # using rapid algorith
- # Juhani Kaukoranta 24.6.2018
- from decimal import *
- import math
- import time
- def binomial(n,k):
- a = math.factorial(n)//(math.factorial(n-k)*math.factorial(k))
- return(a)
- def Zeta3(precision):
- getcontext().prec=precision
- r = Decimal(0)
- sgn = 1
- for n in range(1,2*precision):
- r = r+sgn*Decimal(1)/(n*n*n*binomial(2*n,n))
- sgn = -1*sgn
- return(5*r/2)
- precision = int(input("How many numbers precision, f.eq 100 "))
- time0 = time.clock()
- print("Apery constant , Zeta(3) = ",Zeta3(precision))
- time1 = time.clock()
- print("calculation time ",time1-time0," seconds")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement