There is a lot of incoherence and inconsistencies in sage
hash functions. Two reasons that might explain the design in
some particular situation

* high hash collisions with tuple of integers in Python
(because hash(-1) is -2)

>>> hash((-1,-2)) == hash((-1,-1))
True

* speed. With your version the code would create a tuple (admittedly
this is rather fast).


Le 21/10/2021 à 05:19, Lorenz Panny a écrit :

I've seen handrolled __hash__ methods in quite a few places: They
usually take individual hashes of the data defining the object and
combine them in some arbitrary-looking way.

Two examples I came across recently:
   
https://github.com/sagemath/sage/blob/9.4/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py#L1216
   
https://github.com/sagemath/sage/blob/9.4/src/sage/algebras/quatalg/quaternion_algebra_element.pyx#L219

Q: Is there a good reason things done like this, rather than just
calling hash() on a tuple containing the data of the object?


--
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/7d97ffa7-0354-01e8-65a5-00cee1577b5c%40gmail.com.

Reply via email to