I wanted to implement the Euler Transformation.
My first attempt was:
def EulerTransform(size, a):
R.<x> = ZZ[[]]
f = prod((1 - x^n)^a(n) for n in (1..size)) + O(x^size)
return f.inverse().list()
print(EulerTransform(6, lambda n: factorial(n)))
Now try this with size = 30. I have no idea how long this
takes because after 3 years I turned the computer off.
Am I doing something fundamentally wrong, or is f.inverse()
hopelessly slow?
You can of course implement it differently, but that's not my
question. For those who are interested in the transformation
here the fast variant:
def EulerTrans(a):
@cached_function
def b(n):
if n == 0: return 1
s = sum(sum(d*a(d) for d in divisors(j))*b(n-j) for j in (1..n))
return s//n
return b
b = EulerTrans(lambda n: factorial(n))
print([b(n) for n in range(30)])