First time here? Check out the FAQ!

Ask Your Question
0

polynomials with bounded coefficients

asked 5 years ago

Abhishek gravatar image

updated 5 years ago

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 :

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.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 5 years ago

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]
Preview: (hide)
link

Comments

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

Abhishek gravatar imageAbhishek ( 5 years ago )

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

Stats

Asked: 5 years ago

Seen: 793 times

Last updated: Aug 06 '19