On Thu, Jun 12, 2014 at 10:19 AM, Vincent Delecroix <20100.delecr...@gmail.com> wrote: > 2014-06-12 19:13 UTC+02:00, Robert Bradshaw <rober...@gmail.com>: >> On Thu, Jun 12, 2014 at 12:50 AM, Marc Mezzarobba <m...@mezzarobba.net> >> wrote: >> >>> But here is a similar example right from the Sage library (adapted from >>> http://wiki.sagemath.org/EqualityCoercion): >>> >>> sage: FiniteEnumeratedSet(GF(3)) >>> {0, 1, 2} >>> sage: add(FiniteEnumeratedSet([0,1,2])) >>> 0 >> >> Um, isn't that what you want? The sum of the elements of GF(p^e) for >> any odd prime is zero, which is a handy property. > > In two fresh Sage consoles > {{{ > sage: sum(FiniteEnumeratedSet([0,1,2])) > 3 > }}} > and > {{{ > sage: FiniteEnumeratedSet(GF(3)) > sage: sum(FiniteEnumeratedSet([0,1,2])) > 0 > }}} > > Because FiniteEnumeratedSet has a cache on the input!
Indeed -- no question that this is definitely a bug. Somebody open a ticket (if they haven't already). But I would rather blame the use of caching rather than equality testing. We can certainly fix this bug without changing the definition of "==". > >>>>> sage: {42, QQbar(42)} >>>>> {42, 42} >>>>> sage: {42, SR(42)} >>>>> {42} >>>>> sage: {2^100, SR(2^100)} >>>>> {1267650600228229401496703205376, 1267650600228229401496703205376} >>>> >>>> Hash is not as good as it could/should be for large symbolic integers. >>>> And for AA/QQbar. >>> >>> And do you honestly think this will ever be fixed for all sage objects? >> >> For the common ones at least. And sometimes elements should not define >> hash, as normalizing them is expensive, if even possible. > > Are we allowed to through errors for them? If you do not define hash for an object (or throw an error), then it is not possible to use that object in many data structures, e.g., as keys in dictionaries, in sets, etc. It is possible to use it in lists. Whether or not this is OK, depends on what you're trying to do. If hash wasn't defined on any SR elements, then instead of sage: {42, SR(42)} set([42]) we would get an error, such as: TypeError: unhashable type: ... The drawback is that we would also get errors on this: sage: {pi, e} TypeError: unhashable type: ... -- William -- William Stein Professor of Mathematics University of Washington http://wstein.org -- 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 sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.