Revision history [back]

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]