ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 23 Feb 2021 20:51:49 +0100Set of polynomial under a certain degreehttps://ask.sagemath.org/question/55842/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.
CamilleTue, 23 Feb 2021 18:43:33 +0100https://ask.sagemath.org/question/55842/set-of-polynomial-under-a-certain-degree/Answer by slelievre for <p>How to define the set of polynomials with degree less than or equal to a certain number?</p>
<p>In my program I want to explore all polynomials over a finite field with degree less than or equal to <code>d</code>.</p>
<p>For now, what I do is :</p>
<pre><code>R.<x> = PolynomialRing(GF(2^4))
R.random_element(5)
</code></pre>
<p>But If I want to go through all these elements I can't use that since I get all of them...</p>
<p>Does someone have an idea of what I could do?
Thank you in advance.
Camille</p>
https://ask.sagemath.org/question/55842/set-of-polynomial-under-a-certain-degree/?answer=55848#post-id-55848Polynomial 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:
- [Sage Trac ticket 31432: `monic` option for `polynomials` method of polynomial rings over finite fields](https://trac.sagemath.org/ticket/31432)Tue, 23 Feb 2021 20:51:49 +0100https://ask.sagemath.org/question/55842/set-of-polynomial-under-a-certain-degree/?answer=55848#post-id-55848