-
-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trac #19016: Better hash for Element
As reported on sage-devel [1], `Element` implements its hash based on its string representation. This causes a lot of troubles - it breaks the {{{equality => same hash}}} assumption for finitely presented groups {{{ sage: G = groups.presentation.Cyclic(4) sage: G.cayley_graph().vertices() [1, a, a^2, a^-2, a^3, a^-1] }}} and symbolic expressions {{{ sage: f=sin(x)^2 sage: g=1-cos(x)^2 sage: bool(f == g) True sage: hash(f) == hash(g) False }}} and possibly many others - it is highly incompatible with the `rename` feature (see also #8119) {{{ sage: from sage.structure.element import Element sage: class E(Element): ....: def __init__(self): ....: Element.__init__(self, Parent()) sage: e = E() sage: hash(e) -4965357552728411610 sage: e.rename('hey') sage: hash(e) -6429308858210906323 }}} and similarly, hashing should not be available on any mutable object. - it might be very bad for performance: see #18215 and #18239 for examples There are several possibilities that are currently being discussed: - make it return `0` by default (original proposition of the ticket) - make it raise a `TypeError` by default (as it the case for `SageObject`, see #18246) - let it as it is but raise a Warning [1] https://groups.google.com/d/topic/sage-devel/6rXKkF87Gtc/discussion See also: #19302, #19321, #19331 URL: http://trac.sagemath.org/19016 Reported by: ncohen Ticket author(s): Nils Bruin, Vincent Delecroix Reviewer(s): Volker Braun
- Loading branch information
Showing
20 changed files
with
397 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.