I have the roots of a monic polynomial, i.e.
p(x) = (x-x_1)*...*(x-x_n)
and I need the coefficients a_n, ..., a_0 from
p(x) = x^n + a_{n-1}x^{n-1} + ... + a_0.
Does anybody know a computationally efficient way of doing this? If anybody knows a C/C++ implementation, this would actually be the best. (I already had a look at GSL but it did not provide a function.)
Of course, I know how to to it mathematically. I know, that the coefficient a_i
is the sum of all products of the subsets with n-i
elements. But if I would do it the dumb way, this means to iterate across all subsets, I would need
sum^{n-1}_{k=1} ( k choose n) * (k-1)
multiplications and
sum^n_{k=0} ( k choose n) - n
additions. Hence both terms grow with O(n!)
, which is too much computation to transform a list of n
root into a list of n
coefficients. I believe there must be some intelligent way to reuse most of the intermediate results, but I do not find one.