Advertisement
am1x

sincosdivlog.py

Nov 6th, 2023
561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | Fixit | 0 0
  1. import mpmath as mp
  2. #print(mpmath.libmp.BACKEND)
  3. mp.mp.dps = 128
  4. print(mp.mp)
  5. q = mp.mpc(mp.cos(1.0), mp.sin(1))
  6. qr = 1 / (1 - q)
  7. print(q, qr, sep='\n')
  8.  
  9. def f(x):
  10.     return mp.mpc(mp.cos(x), mp.sin(x)) / mp.log(x)
  11.        
  12. def sumf(n, m = 0):
  13.     res = mp.mpc(0)
  14.     for i in range(2, n):
  15.         res += f(i)
  16.     tail = [f(i) for i in range(n, n + m + 1)]
  17.     for i in range(m):
  18.         #print(i, tail[0] * qr)
  19.         res += tail[0] *  qr
  20.         for j in range(m - i):
  21.             tail[j] = (tail[j + 1] - q * tail[j]) * qr
  22.         tail.pop()
  23.     return res
  24.  
  25. print(sumf(100000, 25))
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement