Skip to content

Commit 5c1309c

Browse files
committed
improve random sampling of quotient-ring elements
1 parent 30b3d78 commit 5c1309c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/sage/rings/quotient_ring.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,30 @@ def term_order(self):
13541354
"""
13551355
return self.__R.term_order()
13561356

1357+
def random_element(self):
1358+
r"""
1359+
Return a random element of this quotient ring obtained by
1360+
sampling a random element of the cover ring and reducing
1361+
it modulo the defining ideal.
1362+
1363+
EXAMPLES::
1364+
1365+
sage: R.<x,y> = QQ[]
1366+
sage: S = R.quotient([x^3, y^2])
1367+
sage: S.random_element() # random
1368+
-8/5*xbar^2 + 3/2*xbar*ybar + 2*xbar - 4/23
1369+
1370+
TESTS:
1371+
1372+
Make sure we are not just getting images of integers in this
1373+
ring (which would be the case if the default implementation
1374+
of this method was inherited from generic rings)::
1375+
1376+
sage: any(S.random_element() not in ZZ for _ in range(999))
1377+
True
1378+
"""
1379+
return self.retract(self.cover_ring().random_element())
1380+
13571381

13581382
class QuotientRing_generic(QuotientRing_nc, ring.CommutativeRing):
13591383
r"""

0 commit comments

Comments
 (0)