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

improve random sampling of quotient-ring elements #37367

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/sage/rings/quotient_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,30 @@ def term_order(self):
"""
return self.__R.term_order()

def random_element(self):
r"""
Return a random element of this quotient ring obtained by
sampling a random element of the cover ring and reducing
it modulo the defining ideal.

EXAMPLES::

sage: R.<x,y> = QQ[]
sage: S = R.quotient([x^3, y^2])
sage: S.random_element() # random
-8/5*xbar^2 + 3/2*xbar*ybar + 2*xbar - 4/23

TESTS:

Make sure we are not just getting images of integers in this
ring (which would be the case if the default implementation
of this method was inherited from generic rings)::

sage: any(S.random_element() not in ZZ for _ in range(999))
True
"""
return self.retract(self.cover_ring().random_element())


class QuotientRing_generic(QuotientRing_nc, ring.CommutativeRing):
r"""
Expand Down