Newton’s Method for Polynomial Logarithms is an algorithm that computes for a formal power series such that in time and space.
Algorithm
Lemma
Proof
- Let . Apply Newton’s Method for Polynomial Inversion to find .
- Let . Apply the Fast Fourier Transform to find and .
- Use the results from 1 to find .
- Apply the Inverse Fast Fourier Transform to find .
- Apply the lemma to find .
This algorithm solves the problem in time and space.
std::vector<std::complex<double>> newton_log(const std::vector<std::complex<double>> &a, int n) {
if (n == 1) {
return {0};
}
std::vector x(n - 1, std::complex(0.));
for (int i = 1; i < std::min(n, int(a.size())); i++) {
x[i - 1] = 1. * i * a[i];
}
auto y = newton_inv(a, n - 1);
int m = std::bit_ceil<u32>(2 * n - 3);
x.resize(m, 0), y.resize(m, 0);
fft(m, x), fft(m, y);
for (int i = 0; i < m; i++) {
x[i] *= y[i];
}
ifft(m, x);
x.resize(n - 1);
x.insert(x.begin(), 0);
for (int i = 1; i < n; i++) {
x[i] /= i;
}
return x;
}