Skip to content

Commit

Permalink
improve random sampling of quotient-ring elements
Browse files Browse the repository at this point in the history
  • Loading branch information
yyyyx4 committed Feb 16, 2024
1 parent 30b3d78 commit 5c1309c
Showing 1 changed file with 24 additions and 0 deletions.
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

0 comments on commit 5c1309c

Please sign in to comment.