Set of polynomial under a certain degree

How to define the set of polynomials with degree less than or equal to a certain number?

In my program I want to explore all polynomials over a finite field with degree less than or equal to d.

For now, what I do is :

R.<x> = PolynomialRing(GF(2^4))
R.random_element(5)


But If I want to go through all these elements I can't use that since I get all of them...

Does someone have an idea of what I could do? Thank you in advance. Camille

edit retag close merge delete

Sort by » oldest newest most voted

Polynomial rings over finite fields have a dedicated method polynomials.

It can generate polynomials of_degree something or of given max_degree.

For monic degree d polynomials, add x^d to polynomials of "max degree one less".

To illustrate, we use the field with four elements so the list stays short enough.

The field and the polynomial ring:

sage: F.<a> = GF(2^2)
sage: F
Finite Field in a of size 2^2

sage: R.<x> = PolynomialRing(F)
sage: R
Univariate Polynomial Ring in x over Finite Field in a of size 2^2


All polynomials of degree up to one:

sage: list(R.polynomials(max_degree=1))
[0
a,
a + 1,
1,
a*x,
a*x + a,
a*x + a + 1,
a*x + 1,
(a + 1)*x,
(a + 1)*x + a,
(a + 1)*x + a + 1,
(a + 1)*x + 1,
x,
x + a,
x + a + 1,
x + 1]


All monic polynomials of degree two:

sage: list(x^2 + p for p in R.polynomials(max_degree=1))
[x^2,
x^2 + a,
x^2 + a + 1,
x^2 + 1,
x^2 + a*x,
x^2 + a*x + a,
x^2 + a*x + a + 1,
x^2 + a*x + 1,
x^2 + (a + 1)*x,
x^2 + (a + 1)*x + a,
x^2 + (a + 1)*x + a + 1,
x^2 + (a + 1)*x + 1,
x^2 + x,
x^2 + x + a,
x^2 + x + a + 1,
x^2 + x + 1]


Aall monic polynomials up to degree 2:

sage: list(x^d + p for d in (0 .. 2) for p in R.polynomials(max_degree=d-1))
[1,
x,
x + a,
x + a + 1,
x + 1,
x^2,
x^2 + a,
x^2 + a + 1,
x^2 + 1,
x^2 + a*x,
x^2 + a*x + a,
x^2 + a*x + a + 1,
x^2 + a*x + 1,
x^2 + (a + 1)*x,
x^2 + (a + 1)*x + a,
x^2 + (a + 1)*x + a + 1,
x^2 + (a + 1)*x + 1,
x^2 + x,
x^2 + x + a,
x^2 + x + a + 1,
x^2 + x + 1]


Providing a keyword argument for generating only monic polynomials is tracked at:

more