Changes between Version 32 and Version 33 of Ticket #19016


Ignore:
Timestamp:
08/15/15 19:27:54 (5 years ago)
Author:
nbruin
Comment:

Shoot. Is there a better way of reverting changes on trac? I ended up cutting and pasting from the change log diff.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #19016 – Description

    v32 v33  
    1 As reported on sage-devel [1], the default hash function implemented in `Element` makes it very likely that `hash` and `==` will not agree. With this branch, the hash is constant and set to 0, making it less likely. Incidentally, it fixes the following bug:
     1As reported on sage-devel [1], the default hash function implemented in `Element` (as `return hash(str(self)))`) causes a lot of troubles
     2
     3- it breaks the {{{equality => same hash}}} assumption for finitely presented groups
    24{{{
    35    sage: G = groups.presentation.Cyclic(4)
     
    57    [1, a, a^2, a^-2, a^3, a^-1]
    68}}}
     9  and symbolic expressions
     10{{{
     11sage: f=sin(x)^2
     12sage: g=1-cos(x)^2
     13sage: bool(f == g)
     14True
     15sage: hash(f) == hash(g)
     16False
     17}}}
     18   and possibly many others
    719
    8 Nathann
     20- it is highly incompatible with the `rename` feature (see also #8119)
     21{{{
     22sage: from sage.structure.element import Element
     23sage: class E(Element):
     24....:     def __init__(self):
     25....:         Element.__init__(self, Parent())
     26sage: e = E()
     27sage: hash(e)
     28-4965357552728411610
     29sage: e.rename('hey')
     30sage: hash(e)
     31-6429308858210906323
     32}}}
     33  and similarly, hashing should not be available on any mutable object.
     34
     35- it might be very bad for performance: see #18215 and #18239 for examples
     36
     37There are several possibilities that are currently being discussed:
     38- make it return `0` by default (original proposition of the ticket)
     39- make it raise a `TypeError` by default (as it the case for `SageObject`, see #18246)
     40- let it as it is but raise a Warning
    941
    1042[1] https://groups.google.com/d/topic/sage-devel/6rXKkF87Gtc/discussion