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.
module top;
parameter size = 5131;
real d, p[0:size-1], p1[0:size-1];
VpFCartesian r[0:size-2];
initial begin
/* set the values of the coefficients of the polynomial p */
$InitM(p, 1.5);
p[0] = 15;
p[1000] = 2;
p [size-2] = 3;
p [size-1] = -6;
/* compute the roots r of polynomial p */
r = $Roots(p);
$PrintM(r, "%e");
/* 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[0];
$PrintM(p1, "%e");
/* compare p and p1 */
d = $VpDistAbsMax(p, p1);
$display("distance = %e\n", d);
end
endmodule // top