On Aug 27, 12:21 pm, Simon King <[EMAIL PROTECTED]> wrote: > On Aug 27, 9:05 pm, "Craig Citro" <[EMAIL PROTECTED]> wrote: > > > I also vote for fast -- but couldn't there be a flag for the slow > > option? Maybe "consistent=True" or something, in case someone really > > wants it? > > AFAIK, the key requirement for a hash function is that equivalent (in > the sense of "==") objects must have the same hash. ... > Hence the "key" question is: Should it be possible to get a dictionary > item by using an equivalent (yet different) key? > Certainly the answer is "yes".
We've already given up on this for Sage. To strictly obey "a == b" implies "hash(a) == hash(b)", then all integers would have to have the same hash, since every integer is equal to either GF(2)(0) or GF(2) (1), and the following proves that the two elements of GF(2) would have the same hash as each other. sage: GF(2)(0) == 0 == GF(3)(0) == 3 == GF(2)(1) True The rule in Sage would be more like: if parent(a) == parent(b) and a == b, then hash(a) == hash(b). This does mean you need to be a little more careful when you use dictionaries, but that seems preferable to having all integers hash the same; and I'm guessing we don't want to give up "6 == GF(2)(0)", which would be the other possibility. If this is the rule we want, then we can have MatrixSpace(GF(2), n, n) hash differently than MatrixSpace(ZZ, n, n) if we want; but sparse and dense matrices would have to hash the same (since MatrixSpace(GF(2), 3, 3) == MatrixSpace(GF(2), 3, 3, sparse=True) ). Carl --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---