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
Hash function of libgap objects #30498
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
comment:4
Is libgap an exception?
|
comment:5
Replying to @dimpase:
Good point! But I would prefer to fix the various interfaces with various tickets. In particular for pari, the hash comes from |
comment:6
I am not convinced that this is a good idea. Why would a hash of differently typed things be equal? To me, the fact that ZZ(2) and int(2) both hash to 2 is more of a hassle, i.e., a hash collision! But I might be wrong - should we discuss this on sage-devel? |
comment:7
https://docs.python.org/3/reference/datamodel.html#object.__hash__
|
comment:8
I am not sure whether this only applies to objects of the same class/type. |
comment:9
Replying to @dimpase:
The python spec has no such requirement, which means that generally, objects for different class/type should compare unequal. In sage, our equality is too liberal to combine useful hashes with keeping to this strict rule:
so we're already forced to be pragmatic about it. Within the same parent, I think we do want it to hold -- otherwise you're better off making the objects not hashable. Outside of that, we can do a reasonable effort, but things will break eventually. People will have to learn that in Sage, you need to normalize your keys prior to putting them in a dictionary, and what that means depends on your application. It will generally mean forcing all the keys into the same parent. It's important to keep hashes cheap too! |
comment:10
Replying to @nbruin:
Regarding that point, |
comment:12
Setting new milestone based on a cursory review of ticket status, priority, and last modification date. |
comment:13
I opened an issue for this against gappy as well: embray/gappy#11 |
Libgap object hash function is not compatible with !Python/Sage
As a consequence
Note that the implementation of
__hash__
is not very subtlehash(str(self))
and could easily be modified to handle properlyintegers and rationals.
Component: packages: standard
Issue created by migration from https://trac.sagemath.org/ticket/30498
The text was updated successfully, but these errors were encountered: