Closed
Description
The generic method divides
that can be found in src/sage/structure/element.pyx
uses quo_rem
(via %
) to test if an element divides another one: return (x % self) == 0
.
For polynomials, depending on the implementations, the method quo_rem
may raise an error if the divisor is not monic (see #16649 for more on this).
This ticket aims at implementing a method divides
for the class Polynomial
, so that it catches the errors in quo_rem
to return False
when it is needed.
Example of a problematic behavior:
sage: R.<x> = PolynomialRing(ZZ, implementation="FLINT")
sage: p = 2*x + 1
sage: q = R.random_element(10)
sage: p.divides(q)
False
sage: R.<x> = PolynomialRing(ZZ, implementation="NTL")
sage: p = R(p)
sage: q = R(q)
sage: p.divides(q)
Traceback (most recent call last):
...
ArithmeticError: division not exact in Z[x] (consider coercing to Q[x] first)
Depends on #16649
Depends on #25277
Component: commutative algebra
Keywords: polynomial, division
Author: Bruno Grenet
Branch/Commit: 94c0390
Reviewer: Vincent Delecroix
Issue created by migration from https://trac.sagemath.org/ticket/19171