Skip to content

Commit

Permalink
sagemathgh-37268: Allow custom degree in random_element of polynomi…
Browse files Browse the repository at this point in the history
…al 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 sagemath#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 sagemath#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
- sagemath#12345: short description why this is a dependency
- sagemath#34567: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#37268
Reported by: Emiel Wiedijk
Reviewer(s): Emiel Wiedijk, Sebastian A. Spindler
  • Loading branch information
Release Manager committed Feb 19, 2024
2 parents 35e7445 + 0e24c1f commit 73907de
Showing 1 changed file with 11 additions and 2 deletions.
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

0 comments on commit 73907de

Please sign in to comment.