@@ -1629,6 +1629,22 @@ cdef class Polynomial(CommutativePolynomial):
16291629 Traceback (most recent call last):
16301630 ...
16311631 NotImplementedError: Multivariate Polynomial Ring in u, v over Integer Ring localized at (u,) does not provide...
1632+
1633+ The behavior of ``xgcd`` over rings like ``ZZ`` are nonstandard, we check the behavior::
1634+
1635+ sage: R.<x> = ZZ[]
1636+ sage: a = 2*x^2+1
1637+ sage: b = -2*x^2+1
1638+ sage: a.inverse_mod(b)
1639+ Traceback (most recent call last):
1640+ ...
1641+ NotImplementedError: The base ring (=Integer Ring) is not a field
1642+ sage: a.xgcd(b)
1643+ (16, 8, 8)
1644+ sage: a*x^2+b*(x^2+1)
1645+ 1
1646+ sage: a*x^2%b # shows the result exists, thus we cannot raise ValueError, only NotImplementedError
1647+ 1
16321648 """
16331649 from sage.rings.ideal import Ideal_generic
16341650 if isinstance (m, Ideal_generic):
@@ -1653,12 +1669,16 @@ cdef class Polynomial(CommutativePolynomial):
16531669 elif g.is_unit():
16541670 return g.inverse_of_unit() * s
16551671 else :
1656- raise ValueError (" Impossible inverse modulo" )
1672+ R = m.base_ring()
1673+ if R.is_field():
1674+ raise ValueError (" Impossible inverse modulo" )
1675+ else :
1676+ raise NotImplementedError (f" The base ring (={R}) is not a field" )
16571677 except NotImplementedError :
16581678 # attempt fallback, return inverse_of_unit() if this is already an unit
16591679 try :
16601680 return a.inverse_of_unit()
1661- except (ArithmeticError , ValueError , NotImplementedError , ZeroDivisionError ):
1681+ except (ArithmeticError , ValueError , NotImplementedError ):
16621682 pass
16631683 raise
16641684 else :
0 commit comments