Skip to content

Commit 044b3aa

Browse files
author
Release Manager
committed
gh-37268: 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. <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [x] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #37268 Reported by: Emiel Wiedijk Reviewer(s): Emiel Wiedijk, Sebastian A. Spindler
2 parents ffa8751 + 0e24c1f commit 044b3aa

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 than 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)