This example works on FinSim 10_07_15 and subsequent versions.
This example shows how to find the roots of a polynomial and how to find the polynomial given the roots. Note that the polynomial is not sparse, as all its coefficients are non-zero, which make the problem more difficult. Also note that the coefficients are in a close range: -6 to 15, which makes the problem easier.
This example run on a laptop with core i7 at 2.4GHz in 13.89 seconds.
parameter size = 5131;
real d, p[0:size-1], p1[0:size-1];
/* set the values of the coefficients of the polynomial p */
p = 15;
p = 2;
p [size-2] = 3;
p [size-1] = -6;
/* compute the roots r of polynomial p */
r = $Roots(p);
/* compute the polynomial p1 corresponding to the roots r */
p1 = $Poly(r);
/* denormalize the polynomial so that the coefficient of the highest order is not one but the same as in polynomial p */
p1 = p1*p;
/* compare p and p1 */
d = $VpDistAbsMax(p, p1);
$display("distance = %e\n", d);
endmodule // top