Skip to content

Commit 90e4486

Browse files
committed
Fix another bug
1 parent 354cdef commit 90e4486

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/sage/rings/polynomial/polynomial_element.pyx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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:

src/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ cdef class Polynomial_integer_dense_ntl(Polynomial):
618618
since they need not exist. Instead, over the integers, we
619619
first multiply `g` by a divisor of the resultant of `a/g` and
620620
`b/g`, up to sign, and return ``g, u, v`` such that
621-
``g = s*self + s*right``. But note that this `g` may be a
621+
``g = u*self + v*right``. But note that this `g` may be a
622622
multiple of the gcd.
623623
624624
If ``self`` and ``right`` are coprime as polynomials over the

0 commit comments

Comments
 (0)