Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change wrapping of FLINT Z/nZ polynomial gcd failure #38719

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions src/sage/libs/flint/nmod_poly_linkage.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -577,18 +577,37 @@ cdef inline int celement_gcd(nmod_poly_t res, nmod_poly_t a, nmod_poly_t b, unsi
True
sage: (G//d)*d == G
True

Check that we catch a case where FLINT fails. These generate the unit
ideal, so their GCD should be 1 (or another unit)::

sage: R.<x> = Integers(121)[]
sage: f = 11*x^2 + 1
sage: f - 61*x*f.derivative()
1
sage: gcd(f, f.derivative())
Traceback (most recent call last):
...
RuntimeError: FLINT gcd calculation failed
"""
if celement_is_zero(b, n):
nmod_poly_set(res, a)
return 0

# A check that the leading coefficients are invertible is *not* sufficient
# FLINT provides no interface for detecting errors here
try:
sig_on()
nmod_poly_gcd(res, a, b)
sig_off()
try:
nmod_poly_gcd(res, a, b)
finally:
sig_off()
except RuntimeError:
raise ValueError("non-invertible elements encountered during GCD")
raise RuntimeError("FLINT gcd calculation failed") from None
kylehofmann marked this conversation as resolved.
Show resolved Hide resolved

cdef unsigned long leadcoeff = nmod_poly_get_coeff_ui(res, nmod_poly_degree(res))
cdef unsigned long modulus = nmod_poly_modulus(res)
if n_gcd(modulus,leadcoeff) == 1:
kylehofmann marked this conversation as resolved.
Show resolved Hide resolved
nmod_poly_make_monic(res, res)

cdef inline int celement_xgcd(nmod_poly_t res, nmod_poly_t s, nmod_poly_t t, nmod_poly_t a, nmod_poly_t b, unsigned long n) except -2:
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/polynomial/polynomial_template.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ cdef class Polynomial_template(Polynomial):
sage: f.gcd(g)
Traceback (most recent call last):
...
ValueError: non-invertible elements encountered during GCD
RuntimeError: FLINT gcd calculation failed
"""
if celement_is_zero(&self.x, (<Polynomial_template>self)._cparent):
return other
Expand Down
Loading