am1x icon

sincosdivlog.py

am1x | PRO | 11/06/23 04:12:29 PM UTC | 0 ⭐ | 1063 👁️ | Never ⏰ | []
Python |

540 B

|

Fixit

|

0 👍

/

0 👎

import mpmath as mp
#print(mpmath.libmp.BACKEND)
mp.mp.dps = 128
print(mp.mp)
q = mp.mpc(mp.cos(1.0), mp.sin(1))
qr = 1 / (1 - q)
print(q, qr, sep='\n')
 
def f(x):
    return mp.mpc(mp.cos(x), mp.sin(x)) / mp.log(x)
        
def sumf(n, m = 0):
    res = mp.mpc(0)
    for i in range(2, n):
        res += f(i)
    tail = [f(i) for i in range(n, n + m + 1)]
    for i in range(m):
        #print(i, tail[0] * qr)
        res += tail[0] *  qr
        for j in range(m - i):
            tail[j] = (tail[j + 1] - q * tail[j]) * qr
        tail.pop()
    return res
 
print(sumf(100000, 25))
 

Comments