Macaulay2 / M2

The primary source code repository for Macaulay2, a system for computing in commutative algebra, algebraic geometry and related fields.
https://macaulay2.com
350 stars 235 forks source link

submatrix keeps hash unchanged #997

Open mahrud opened 5 years ago

mahrud commented 5 years ago

Despite the fact that submatrix makes a copy of mutable matrices, hash of the two objects stays the same.

i1 : A = mutableMatrix {{10}}
o1 = | 10 |
o1 : MutableMatrix

i2 : B = submatrix(A,{0},{0})
o2 = | 10 |
o2 : MutableMatrix

i3 : A_(0,0) = 11
o3 = 11

i4 : B_(0,0) = 12
o4 = 12

i5 : A
o5 = | 11 |
o5 : MutableMatrix

i6 : B
o6 = | 12 |
o6 : MutableMatrix

i7 : hash A == hash B
o7 = true

i8 : hash A
o8 = 1527355229
DanGrayson commented 5 years ago

It should be easy to make the submatrix routine produce a new hash code, the next one in the sequence. It's probably doing a low-level copy operation that simply copies the hash code, too.

mahrud commented 5 years ago

Does hash also depend on the location of the object in ram?

I wanted to use it to distinguish pointers to the same object. Is there a way to do that? (I understand that the location of an object can change, but it can be used to detect when two mutable objects are pointing to the same location)

DanGrayson commented 5 years ago

Does hash also depend on the location of the object in ram?

No. One design principle used is that Macaulay2 should give the same answers on all machines.

I wanted to use it to distinguish pointers to the same object. Is there a way to do that? (I understand that the location of an object can change, but it can be used to detect when two mutable objects are pointing to the same location)

No, there is no way to do that. It doesn't make much sense to want that either -- pointers to the same object have exactly the same behavior, and it's the object they point to that is what's important for us.