#18383: Coercion and comparison for alternating sign matrices
-------------------------------------+-------------------------------------
       Reporter:  vdelecroix         |        Owner:
           Type:  enhancement        |       Status:  needs_work
       Priority:  major              |    Milestone:  sage-6.7
      Component:  combinatorics      |   Resolution:
       Keywords:                     |    Merged in:
        Authors:  Vincent Delecroix  |    Reviewers:
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
  u/vdelecroix/18383                 |  390e2d7cf57899cde4c7b096ef5b97f0be909574
   Dependencies:                     |     Stopgaps:
-------------------------------------+-------------------------------------

Comment (by vdelecroix):

 Replying to [comment:10 tscrim]:
 > Surely we aren't forcing everything to have a total ordering via a
 `_cmp_` (and are telling people to use `cmp` to do comparisons)? If so,
 then we'll never be able to switch to Python3.

 Please, stop talking about Python 3 since Cython is very different from
 Python from that point of view. To handle comparisons of elements in Sage
 and if you want the coercion to be involved then you should either
 implement:
  - `_cmp_(self, other)` (the simplest option)
  - `_richcmp_(self, other, op)`
 This is a choice for the programmer and he/she can even implement both. I
 am not forcing anybody to use one or the other, but the first one is by
 far easier. This is independent of whatever Python version.

 The subtle difference that you seem to care about between rich comparisons
 and cmp does not exists even in Python 2
 {{{
 class A:
     def __init__(self, value):
         self.x = value
     def __lt__(self, other):
         print "LT"
         return self.x < other.x
     def __le__(self, other):
         print "LE"
         return self.x <= other.x
     def __eq__(self, other):
         print "EQ"
         return self.x == other.x
     def __ne__(self, other):
         print "NE"
         return self.x != other.x
     def __ge__(self, other):
         print "GE"
         return self.x >= other.x
     def __gt__(self, other):
         print "GT"
         return self.x > other.x
 }}}
 Then
 {{{
 sage: a = A(1)
 sage: b = A(2)
 sage: cmp(a,b)
 EQ
 LT
 -1
 }}}
 This difference is just a Cython feature that we are not using much.

--
Ticket URL: <http://trac.sagemath.org/ticket/18383#comment:11>
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