# polynomials with bounded coefficients

I have a list L, and would like to construct all polynomials of degree d, with coefficients from the list. An example is the following :

SET=[];
K.<a>=FiniteField(17);
F.<x> = PolynomialRing(K,'x');
for f in F.monics( of_degree=8):
S=f.coefficients(sparse=False);
if S==([K(1),K(16)]):
SET=SET+[f];
print SET;


The above command is too time consuming. Is there a simpler way, when we can get the output in less time.

edit retag close merge delete

Sort by » oldest newest most voted

You waste a lot of time in creating all polynomials and then selecting the good ones.

Ton generate only the polynomials with coefficients from a list, you can use the product function of the itertoolsstandard module to make the product of your list d+1 times and construct your polynomials from its elements, with the additional trick that if F is a polynomial ring, and t is a tuple of elements of the base ring of F, then K(t) is the polynomial whose coefficients are the elements of t. This leads to:

sage: L = [K(1), K(16)]
sage: d = 8

sage: from itertools import product
sage: P = product(L, repeat=d+1)

sage: SET = [F(coeffs) for coeffs in P]

more

Thanks a lot, didn't know of this function.

( 2019-08-06 03:49:59 -0600 )edit