Changes between Version 31 and Version 32 of Ticket #19016


Ignore:
Timestamp:
08/15/15 19:11:23 (5 years ago)
Author:
nbruin
Comment:

Replying to vdelecroix:

Element does implement the return hash(str(self)) behavior. So this will incidentally be fixed with this ticket...

Aw, that's unfortunate. Also, I'm pretty sure removing default hashes on elements is going to be a much more involved problem. This ticket should probably keep its general function and be retitled to: remove default hash on Element.

I have made #19038 for the FPGroup issue (where we're in much better shape in many individual cases)

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #19016

    • Property Milestone changed from sage-6.9 to sage-duplicate/invalid/wontfix
  • Ticket #19016 – Description

    v31 v32  
    1 As 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
     1As 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:
    42{{{
    53    sage: G = groups.presentation.Cyclic(4)
     
    75    [1, a, a^2, a^-2, a^3, a^-1]
    86}}}
    9   and symbolic expressions
    10 {{{
    11 sage: f=sin(x)^2
    12 sage: g=1-cos(x)^2
    13 sage: bool(f == g)
    14 True
    15 sage: hash(f) == hash(g)
    16 False
    17 }}}
    18    and possibly many others
    197
    20 - it is highly incompatible with the `rename` feature (see also #8119)
    21 {{{
    22 sage: from sage.structure.element import Element
    23 sage: class E(Element):
    24 ....:     def __init__(self):
    25 ....:         Element.__init__(self, Parent())
    26 sage: e = E()
    27 sage: hash(e)
    28 -4965357552728411610
    29 sage: e.rename('hey')
    30 sage: 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 
    37 There 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
     8Nathann
    419
    4210[1] https://groups.google.com/d/topic/sage-devel/6rXKkF87Gtc/discussion