#17427: x==y while hash(x)!=hash(y) with SchemeMorphism_point_projective_field
---------------------------------+------------------------
       Reporter:  ncohen         |        Owner:
           Type:  defect         |       Status:  new
       Priority:  major          |    Milestone:  sage-6.5
      Component:  PLEASE CHANGE  |   Resolution:
       Keywords:                 |    Merged in:
        Authors:                 |    Reviewers:
Report Upstream:  N/A            |  Work issues:
         Branch:                 |       Commit:
   Dependencies:                 |     Stopgaps:
---------------------------------+------------------------

Comment (by nbruin):

 Replying to [comment:5 bhutz]:
 > Notice that the sage developers guide says the following about hash:
 >
 > '“The only required property is that objects which compare equal have
 the same hash value.” This is an assumption made by the Python language,
 which in Sage we simply cannot make!'

 That's just because the use of non-injective coercion maps means that
 equality testing in sage isn't transitive when allowing elements from
 multiple parents:
 {{{
 sage: 1 == GF(5)(1)
 True
 sage: GF(5)(1) == 6
 True
 sage: 1 == 6
 False
 }}}
 which indeed means that you shouldn't have a dictionary where you use both
 integers and finite field elements as keys. But at least there's an easy
 rule there: If you use sage objects as keys in a dict, make sure they all
 have the same parent, or make sure that you really know what you're doing.

 If you can't even have a hash that works properly between elements of the
 same parent then you shouldn't make those elements hashable. The hash will
 be useless and it's misleading to have. This happened to p-adics, where
 `==` was chosen to be too permissive to be transitive (they were
 considered equal if their associated disks had non-empty intersection),
 and indeed they are slated to lose their hash (see #11895)
 {{{
 sage: 1+O(k(9)) == 1+O(k(3))
 True
 sage: 1+O(k(3)) == 4+O(k(9))
 True
 sage: 1+O(k(9)) == 4+O(k(9))
 False
 }}}
 (note it's the same issue as with ZZ and finite fields, but now inside the
 same parent)

 As long as you're taking projective space over integral domains with a
 constructible field of fractions, you can just normalize a non-zero
 coordinate to 1 and hash that (provided the implementation of the field of
 fractions has an appropriate hash (fields that are a finite extension of a
 FoF of a PID should be OK, if implemented correctly, and Noether
 Normalization gives us that basically all fields we'll meet in sage are of
 that type)). Yes, hashing is hard :-).

 If you want to take projective space over non-integral domains, I think
 you'll have bigger problems elsewhere.

--
Ticket URL: <http://trac.sagemath.org/ticket/17427#comment:6>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to