Skip to content

Commit 3ff46e3

Browse files
committed
Allow custom degree in random_element of polynomial quotient ring
Currently, the `random_element` function of the polynomial quotient ring passes all arguments through to the base ring. However, the random_element function itself passes a default degree to the base ring, based on the degree of the quotient ring. So, overwriting the degree in kwargs gives a TypeError. Therefore, detect the `degree` argument manually, such that the user can overrride the default degree.
1 parent 30b3d78 commit 3ff46e3

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/sage/rings/polynomial/polynomial_quotient_ring.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,12 +1260,18 @@ def polynomial_ring(self):
12601260

12611261
cover_ring = polynomial_ring
12621262

1263-
def random_element(self, *args, **kwds):
1263+
def random_element(self, degree=None, *args, **kwds):
12641264
"""
12651265
Return a random element of this quotient ring.
12661266
12671267
INPUT:
12681268
1269+
- ``degree`` - Optional argument: either an integer for fixing the
1270+
degree, or a tuple of the minimum and maximum degree. By default the
1271+
degree is n - 1 with n the degree of the polynomial ring. Note that
1272+
the degree of the polynomial is fixed before the modulo calculation.
1273+
So when `degree` is bigger then the degree of the polynomial ring, the
1274+
degree of the returned polynomial would be lower than `degree`.
12691275
- ``*args``, ``**kwds`` - Arguments for randomization that are passed
12701276
on to the ``random_element`` method of the polynomial ring, and from
12711277
there to the base ring
@@ -1283,8 +1289,11 @@ def random_element(self, *args, **kwds):
12831289
sage: F2.random_element().parent() is F2
12841290
True
12851291
"""
1292+
if degree is None:
1293+
degree = self.degree() - 1
1294+
12861295
return self(self.polynomial_ring().random_element(
1287-
degree=self.degree() - 1, *args, **kwds))
1296+
degree=degree, *args, **kwds))
12881297

12891298
@cached_method
12901299
def _S_decomposition(self, S):

0 commit comments

Comments
 (0)