|
Size: 716
Comment:
|
Size: 2376
Comment:
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 3: | Line 3: |
| Equality and Coercion could be harmful ====================================== |
Equality using Coercion considered harmful? =========================================== |
| Line 6: | Line 6: |
| The goal of this page is to gather all problems due to equality accepting coercion in borderline cases:: | Currently, Sage specifies that, upon comparing with ``a==b`` two objects `a` and `b` that do not have the same parent, a coercion is attempted to put them in the same parent. To prepare a discussion on whether that specification is viable in the long run, we are gathering here (borderline?) use cases where this behaviour is harmful. :: |
| Line 14: | Line 16: |
| sage: dd | However Python 2.7 documentation specifies:: object.__hash__(self) Called by built-in function hash() and for operations on members of hashed collections including set, frozenset, and dict. __hash__() should return an integer. The only required property is that objects which compare equal have the same hash value; As a first consequence of the above behavior:: sage: {3.1415926535897932: 'approx', pi: 'exact'} |
| Line 19: | Line 31: |
| as a consequence:: | And also:: |
| Line 32: | Line 44: |
| }}} | More strange consequences when using UniqueRepresentation --------------------------------------------------------- :: sage: F1 = FiniteEnumeratedSet([0.000000]) sage: F2 = FiniteEnumeratedSet([0]) sage: F1 is F2 True sage: F2.list() [0.000000000000000] sage: An example showing that Sage's specifications clashes with Python's specifications ------------------------================------------------------------------------ :: sage: S = SymmetricFunctions(QQ) sage: x = S.s()[5] sage: y = S.p()(x) sage: x == y True sage: hash(x), hash(y) (-1840429907820881728, 5178019317311573726) It's surely syntactically nice to have x == y evaluate True after a coercion. However enforcing that the two hash functions be the same would be simply impossible: this would force to systematically coerce any symmetric function to some fixed base for computing the hash function, and we just can't afford that. |
