#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:15 tscrim]:
> Replying to [comment:14 vdelecroix]:
> > Replying to [comment:13 tscrim]:
> > > We have to care about Python3 because it is the way going forward.
The subtlety has come from us implementing a `__cmp__` at the general
`Element` level, which gets called by the `cmp` first, and then instead of
the default Python implementation of checking `__eq__` and `__lt__`, it
tries to call `_cmp_` and then `_richcmp_`. This is a subtly caused by the
current machinery in Sage. We need a mechanism which falls back to the
usual Python rich comparisons for compatibility (although perhaps we need
to make a single underscored version to work with coercion, but that is a
question for sage-devel and I think there's already discussions about
this).
> >
> > This is not that simple because at the level of the C API `__eq__`,
`__lt__` etc does not exist. So there will be a huge difference between
extension classes (ie Cython) and Python classes (ie Python). The uniform
way that is proposed is precisely to use `_cmp_` or `_richcmp_` and avoid
`__eq__`, etc.
>
> The uniform way would be to have the generic `_richcmp_` default back to
using the python `__eq__`, etc. It may not be simple to implement, but it
is the IMO correct way to do things as we should not be making ourselves
less Python3 compliant. Plus I thought by having `_richcmp_` being a
Python method, we could then call the `__lt__`, or at least use `getattr`.
Moreover, this is only a problem for doing comparisons with `cmp`, which
will be moot once we do switch.
We can not do that. The method `__richcmp__` (and hence `_richcmp_`) is
not used at all if `__eq__`, `__lt__`, etc are implemented in a Python
class.
> > The fact that there is a global `__cmp__` in `Element` might be a
problem but this is rather disjoint from the present ticket: for ASM we
want coercion to be involved.
>
> It's quite relevant because it is part of your proposal. In the current
version of Sage, if the other element is not an ASM, then it lifts itself
to the matrix space and does the comparison there (in that it compares
against its defining matrix).
Do you have an example involving rich comparisons that differ?
Vincent
--
Ticket URL: <http://trac.sagemath.org/ticket/18383#comment:16>
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.