Changes between Initial Version and Version 3 of Ticket #18305


Ignore:
Timestamp:
Apr 28, 2015, 12:20:26 PM (8 years ago)
Author:
Vincent Delecroix
Comment:

Another example: embedded number fields in RR. If you want that rich comparisons coincide with the order on RR then == and != are cheap but not <, <=, > and >=.

Do you agree with the new description?

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #18305 – Description

    initial v3  
    1 In #17890 the comparisons of elements (i.e. through `__cmp__` and `__richcmp__`) has been simplified. In order for elements to take benefit of the coercion framekwork they should either implement `_cmp_(left,right)` and/or `_richcmp_(left,right,op)`.
     1In #17890 the comparison of elements (i.e. `Element.__cmp__`) and rich comparison of elements (i.e. `Element.__richcmp__`) have been simplified.
    22
    3 In particular, it is discouraged to implement `__eq__` and `__ne__` if coercion has to be involved. It would also be simpler if no element implements `__cmp__`.
     31 .If coercion has to be involved then the Python elements should implement:
     4 - `_richcmp_(left, right, op)` for rich comparisons (i.e. operators `<`, `<=`, `==`, `!=`, `>=` and `>=`)
     5 - `_cmp_(left, right)` for comparisons (i.e. when calling `cmp(x,y)`)
     6  In these two methods, it can be assumed that both arguments `left` and `right` are subclasses of `Element` with the same parent. If `_cmp_` makes sense it is possible to implement it only. If an element wants to implement `==` and `!=` only, then it should just raise a `NotImplementedError` for other operators in `_richcmp_(left,right,op)`.
     7
     82 . If comparison needs to not avoid coercion, then:
     9 - rich comparison is possible through `__eq__`, `__ne__`, `__lt__`, etc (and all of these should be implemented)
     10 - comparison is possible via `__cmp__`
    411
    512In this ticket:
    613 - make everything needed for rich comparisons available from Python (i.e. `Py_EQ`, `Py_NE`, etc as well as `rich_to_bool/rich_to_bool_sgn`)
    7  - we check the sage libraries for occurrences of `__eq__`/`__ne__`/`__cmp__` in elements and see whether these can be simplified
     14 - check the sage libraries for occurrences of `__eq__`/`__ne__`/`__cmp__` in elements and see whether these can be simplified
    815     - #18303 takes care of `sage.rings.qqbar`
    916 - update the documentation in `sage.structure.Element`
     17 - remove the test in the default `Element._cmp_` since an element implementing `__cmp__` wants to avoid coercion