Ask Your Question

polynomials with bounded coefficients

asked 2019-08-06 10:05:16 +0200

Abhishek gravatar image

updated 2019-08-06 10:18:02 +0200

tmonteil gravatar image

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 :

F.<x> = PolynomialRing(K,'x');
for f in F.monics( of_degree=8):
    if S==([K(1),K(16)]):
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 flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2019-08-06 10:27:52 +0200

tmonteil gravatar image

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]
edit flag offensive delete link more


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

Abhishek gravatar imageAbhishek ( 2019-08-06 10:49:59 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-08-06 10:05:16 +0200

Seen: 54 times

Last updated: Aug 06 '19