#19171: Add a method `divides` to Polynomial
-------------------------------------+-------------------------------------
       Reporter:  bruno              |        Owner:
           Type:  defect             |       Status:  needs_review
       Priority:  major              |    Milestone:  sage-7.3
      Component:  commutative        |   Resolution:
  algebra                            |
       Keywords:  polynomial,        |    Merged in:
  division                           |
        Authors:  Bruno Grenet       |    Reviewers:  Vincent Delecroix
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
  u/bruno/t19171_divides_poly        |  ac43c02c86eb8884bc3d7fa4013f78aef1e34803
   Dependencies:  #16649             |     Stopgaps:
-------------------------------------+-------------------------------------
Changes (by bruno):

 * status:  needs_work => needs_review


Comment:

 Replying to [comment:9 vdelecroix]:
 > You would better use `coerce_binop` from `sage.structure.element` rather
 than a manually handled coercion.

 Done.

 > Why is this code specific to polynomials?

 I tried to explain the reasons in the description: For polynomials over
 (say) `ZZ`, the euclidean division is not well defined. The problem occurs
 when the leading coefficient is not invertible. There are several ways to
 deal with this problem, and different implementations in Sage use
 different conventions (see #16649 for pointers on this). As a result,
 testing divisibility by invoking `self % p == 0` can lead to
 `ArithmeticError` for polynomials: But when this exception is raised, we
 know that `self` does not divide `p`.¹ That's why I decided to add this
 new method which only differs from the generic one by the fact it catches
 the exception.

 I could have changed the generic method instead to catch an
 `ArithmeticError` and return `False` in such case, but though I am pretty
 confident that it makes sense for polynomials, I am much less confident
 concerning other rings.

 ¹ "We know" is maybe a too strong assumption. In #16649, I did changes
 that ensure that the assumption holds for all ''current implementations''
 of polynomials in Sage. (This was not the case before.) Yet, future
 implementations may break this rule. This may imply that we shouldn't
 simply rely on `quo_rem` to test divisibility.

--
Ticket URL: <https://trac.sagemath.org/ticket/19171#comment:12>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to