Fast way to obtain the first terms of the exponentiation of a taylor series?

73 Views Asked by At

Suppose I want to compute the number of ways $w(n)$ to partition an integer $n$ into distinct odd parts $(n \sim 10^7)$. The generating function $W(x)$ of $w(n)$ is $$W(x) = \sum_{k = 0}^\infty w(k)x^k = \prod_{k = 0}^\infty (1 + x^{2k + 1})$$ If I multiply the first $n$ terms directly, this would result in $O(n^2)$ additions, which is too slow. However, it is relatively easy to compute $\log W(x)$: $$\log W(x) = \sum_{k = 0}^\infty \log(1 + x^{2k + 1}) = \sum_{k = 0}^\infty \sum_{m = 1}^\infty \frac{x^{m(2k + 1)}}{m}$$ Since I only need the first $n$ terms, for each $k$ I need to add at most $n/k$ terms, and the total time reduces to $$n\left(\frac{1}{2} + \frac{1}{3} + \cdots\right) = nH_n = O(n\log n)$$ However, I now have to obtain the coefficients of $W(x)$ from those of $\log W(x)$. Is there a fast way to compute this?

1

There are 1 best solutions below

0
On BEST ANSWER

I just realized this is a duplicate question, and has been solved very long ago.

Efficient series expansion of exp(p(x))