On Thu, Mar 17, 2011 at 4:06 AM, David Roe <r...@math.harvard.edu> wrote:
>> > for is a function of the hash of its elements to
>> > satisfy equal matrices over different parents having the same hash.
>>
>> Err, sorry, I don't manage to parse the end of the sentence. Do you
>> mind reformulating?
>
> I think what Robert was trying to say is that if R and S are different
> rings, and M is a matrix over R then
> hash(M.change_ring(S)) == hash(M) as much as possible.

Exactly.


On Thu, Mar 17, 2011 at 7:29 AM, Jeroen Demeyer <jdeme...@cage.ugent.be> wrote:
> On 2011-03-17 15:04, Jason Grout wrote:
>> def hash(self):
>>     h=0
>>     for i,j,entry in m.nonzero_entries(): # nonzero entries for sparse
>> matrices
>>        h^=hash(entry)^i^j
>>     return h
>
> Since you're only xorring, this will give a lot of collisions.  I think
> something like
>
> def hash(self):
>    n = m.ncols()
>    h = (m.nrows() + m.ncols())**2 + n
>    for i,j,entry in m.nonzero_entries():
>        h ^= hash(entry)*(i*n + j + 1)
>    return h
>
> has less chance of collisions.  Of course everything should be computed
> as a C long.

This is almost the current definition, see
http://hg.sagemath.org/sage-main/file/361a4ad7d52c/sage/matrix/matrix_dense.pyx#l37
Initializing h with the dimension and not ignoring the 0th entry would
be an improvement. We still need to support specialized
implementations such as
http://hg.sagemath.org/sage-main/file/361a4ad7d52c/sage/matrix/matrix_mod2_dense.pyx#l299
which is 100s of times faster than the generic implementation (and
dense mod 2 matrices tend to be large).

- Robert

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to