Skip to content

Commit ed69335

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 ed69335

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Diff for: src/sage/rings/finite_rings/integer_mod.pyx

+14-1
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,19 @@ cdef class IntegerMod_abstract(FiniteRingElement):
11741174
sage: Mod(1/25, next_prime(2^90)).sqrt()^(-2)
11751175
25
11761176
1177+
Error message as requested in :issue:`38802`::
1178+
1179+
sage: sqrt(Mod(2, 101010), all=True)
1180+
Traceback (most recent call last):
1181+
...
1182+
NotImplementedError: Finding all square roots in extensions is not implemented; try extend=False to find only roots in the base ring Zmod(n).
1183+
1184+
Using the suggested ``extend=False`` works and returns an empty list
1185+
as expected::
1186+
1187+
sage: sqrt(Mod(2, 101010), all=True, extend=False)
1188+
[]
1189+
11771190
::
11781191
11791192
sage: a = Mod(3, 5); a
@@ -1260,7 +1273,7 @@ cdef class IntegerMod_abstract(FiniteRingElement):
12601273
z = Q.gen()
12611274
if all:
12621275
# TODO
1263-
raise NotImplementedError
1276+
raise NotImplementedError("Finding all square roots in extensions is not implemented; try extend=False to find only roots in the base ring Zmod(n).")
12641277
return z
12651278
if all:
12661279
return []

0 commit comments

Comments
 (0)