Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom degree in random_element of polynomial quotient ring #37268

Merged
merged 2 commits into from
Feb 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/sage/rings/polynomial/polynomial_quotient_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -1260,12 +1260,18 @@ def polynomial_ring(self):

cover_ring = polynomial_ring

def random_element(self, *args, **kwds):
def random_element(self, degree=None, *args, **kwds):
"""
Return a random element of this quotient ring.

INPUT:

- ``degree`` - Optional argument: either an integer for fixing the
degree, or a tuple of the minimum and maximum degree. By default the
degree is n - 1 with n the degree of the polynomial ring. Note that
the degree of the polynomial is fixed before the modulo calculation.
So when `degree` is bigger than the degree of the polynomial ring, the
degree of the returned polynomial would be lower than `degree`.
- ``*args``, ``**kwds`` - Arguments for randomization that are passed
on to the ``random_element`` method of the polynomial ring, and from
there to the base ring
Expand All @@ -1283,8 +1289,11 @@ def random_element(self, *args, **kwds):
sage: F2.random_element().parent() is F2
True
"""
if degree is None:
degree = self.degree() - 1

return self(self.polynomial_ring().random_element(
degree=self.degree() - 1, *args, **kwds))
degree=degree, *args, **kwds))

@cached_method
def _S_decomposition(self, S):
Expand Down
Loading