Skip to content

Commit 616133e

Browse files
committed
Improve NotImplementedError for sqrt(Mod(a,n), all=True)
When sqrt(Mod(a,n), all=True) is called for a non-square 'a' with the default extend=True, the resulting NotImplementedError was very generic. Improved the error message to suggest trying extend=False to find roots only within the base ring Zmod(n), as discussed in the issue. Included a doctest .
1 parent 871ba9d commit 616133e

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/sage/rings/finite_rings/integer_mod.pyx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,20 @@ cdef class IntegerMod_abstract(FiniteRingElement):
11741174
sage: Mod(1/25, next_prime(2^90)).sqrt()^(-2)
11751175
25
11761176
1177+
Check the error message when ``extend=True`` (default) and ``all=True``
1178+
is used for a non-square, as requested in :issue:`38802`::
1179+
1180+
sage: sqrt(Mod(2, 101010), all=True)
1181+
Traceback (most recent call last):
1182+
...
1183+
NotImplementedError: Finding all square roots in extensions is not implemented; try extend=False to find only roots in the base ring Zmod(n).
1184+
1185+
Using the suggested ``extend=False`` works and returns an empty list
1186+
as expected::
1187+
1188+
sage: sqrt(Mod(2, 101010), all=True, extend=False)
1189+
[]
1190+
11771191
::
11781192
11791193
sage: a = Mod(3, 5); a
@@ -1260,7 +1274,7 @@ cdef class IntegerMod_abstract(FiniteRingElement):
12601274
z = Q.gen()
12611275
if all:
12621276
# TODO
1263-
raise NotImplementedError
1277+
raise NotImplementedError("Finding all square roots in extensions is not implemented; try extend=False to find only roots in the base ring Zmod(n).")
12641278
return z
12651279
if all:
12661280
return []

0 commit comments

Comments
 (0)