Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In richcmp, fall back to reversed operation if coercion fails #21163

Closed
jdemeyer opened this issue Aug 4, 2016 · 12 comments
Closed

In richcmp, fall back to reversed operation if coercion fails #21163

jdemeyer opened this issue Aug 4, 2016 · 12 comments

Comments

@jdemeyer
Copy link

jdemeyer commented Aug 4, 2016

Change the implementation of x.__richcmp__(y, op) to try y.__richcmp__(x, revop) if y not a Sage Element and coercion fails. In Python terms: if x.__ge__(y) fails, try y.__le__(x). This is precisely what Python does when a comparison returns NotImplemented.

If this reversed operation is not implemented (either the type does not define comparisons or the comparison returns NotImplemented), go on as usual. Because of this, we cannot just return NotImplemented in the coercion model, we need to implement the reversing ourselves.

In #20767, the analogous thing was done for arithmetic.

Component: coercion

Author: Jeroen Demeyer

Branch/Commit: b3ea04f

Reviewer: Frédéric Chapoton

Issue created by migration from https://trac.sagemath.org/ticket/21163

@jdemeyer jdemeyer added this to the sage-7.3 milestone Aug 4, 2016
@jdemeyer

This comment has been minimized.

@jdemeyer

This comment has been minimized.

@jdemeyer

This comment has been minimized.

@jdemeyer

This comment has been minimized.

@jdemeyer

This comment has been minimized.

@jdemeyer
Copy link
Author

jdemeyer commented Aug 4, 2016

@jdemeyer
Copy link
Author

jdemeyer commented Aug 4, 2016

Commit: b3ea04f

@jdemeyer
Copy link
Author

jdemeyer commented Aug 4, 2016

New commits:

b3ea04fTry reversed operation in richcmp if coercion fails

@fchapoton
Copy link
Contributor

comment:8

ok, looks good to me. Nice formula for the revop involution.

@fchapoton
Copy link
Contributor

Reviewer: Frédéric Chapoton

@jdemeyer
Copy link
Author

jdemeyer commented Aug 5, 2016

comment:9

Replying to @fchapoton:

ok, looks good to me. Nice formula for the revop involution.

Thanks. That was a nice exercise :-)

@vbraun
Copy link
Member

vbraun commented Aug 7, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants