#16127: Fix comparison of PARI objects
-------------------------------------+-------------------------------------
       Reporter:  pbruin             |        Owner:
           Type:  defect             |       Status:  needs_review
       Priority:  critical           |    Milestone:  sage-6.4
      Component:  interfaces         |   Resolution:
       Keywords:  pari comparison    |    Merged in:
        Authors:  Peter Bruin        |    Reviewers:  Jeroen Demeyer
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
  u/pbruin/16127-pari_comparison     |  0e0b4da393fa63c54e6f8c3ade0309ec198c2ffe
   Dependencies:                     |     Stopgaps:
-------------------------------------+-------------------------------------

Comment (by pbruin):

 Replying to [comment:25 jdemeyer]:
 > I'm slightly worried about the fact that sorting using `cmp` is not
 supported in Python 3.
 I find this a strange choice, but I guess we'll have to live with it...
 > It seems the Python 3 way is to define either a sorting key (which isn't
 applicable here) or just use the rich comparison operators.
 There are various solutions:
 1. Python (3, at least) has a function `cmp_to_key` that converts a `cmp`
 function into a `key` function, so instead of `cmp=cmpfunc` you can
 specify `key=cmp_to_key(cmpfunc)`.  (The key returned by
 `cmp_to_key(cmpfunc)` for a given object `obj` is a new object wrapping
 `obj` with comparison operators implemented using `cmpfunc`.)  This looks
 artificial and inefficient.
 2. When sorting polynomials (which are the only kind of non-ordered PARI
 objects that is currently sorted somewhere in the Sage library), one can
 specify `key=lambda f: f.list()`.
 3. Any list of PARI objects can be sorted by converting it into a `t_VEC`
 and using one of several built-in PARI sorting functions.
 I don't think the disappearance of the `cmp` keyword for sorting is
 serious enough that it forces us to keep `__cmp__()` and `__richcmp__()`
 consistent.  (In principle, if we adopt 2. or 3. above, we could even
 think about removing `gen._cmp_c_impl()`, so the generic `Element` code
 automatically falls back to using rich comparison to implement
 `__cmp__()`.  I'm not sure if this is a good idea, though.)

--
Ticket URL: <http://trac.sagemath.org/ticket/16127#comment:26>
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 http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to