Macaulay2 / M2

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

Inconsistent behaviour of == for modules #3016

Closed pzinn closed 12 months ago

pzinn commented 12 months ago

As part of trying to fix https://github.com/Macaulay2/M2/issues/1273, I encountered the following bug (or at least, inconsistent behaviour):

i1 : R=QQ[x,y]

o1 = R

o1 : PolynomialRing

i2 : M=ideal(x,y)/ideal(x^2,y)

o2 = subquotient (| x y |, | x2 y |)

                               1
o2 : R-module, subquotient of R

i3 : trim M

o3 = subquotient (| x |, | y x2 |)

                               1
o3 : R-module, subquotient of R

i4 : trim M == M

o4 = true

i5 : M'=ideal x/ideal(x^2,x*y)

o5 = subquotient (| x |, | x2 xy |)

                               1
o5 : R-module, subquotient of R

i6 : M==M'

o6 = false

i7 : trim M==M' -- should definitely be true

o7 = false

Note that all these modules are equal. If anything, one could argue that M and trim M are not exactly the same since the generators are different, so the modules are isomorphic but technically not equal; but M2 doesn't seem to care about that. However, it does notice that the relations of M and M' are different -- even though that makes no difference (in particular, trim M and M' are strictly equal). The corresponding code is tagged as "temporary"...

pzinn commented 12 months ago

OK I think I understand the logic. I implicitly assumed that when writing M/N we really meant $M/(N\cap M)$, whereas after checking the doc, I see that it's $(M+N)/N$ instead. then the answers as given are correct. closing.

mahrud commented 12 months ago

Playing with @d-torrance's PRs, I think this is a bug though:

R = QQ[x,y,z,w];
M = (comodule monomialCurveIdeal(R, {1,2,3}))^3;
m = map(M, , {{z^2}, {y*z}, {y^2}})
v1 = vector m
v2 = m_0
v1 === v2      -- false!
v1 ==  v2      -- false!! (should definitely call reduce)
v1 - v2 == 0_M -- false!!! (also v1 - v2 == 0 should work)

While:

peek v2 == peek v1 -- true XD

I think it's because of this:

i65 : source matrix v1

       1
o65 = R

o65 : R-module, free, degrees {2}

i66 : source matrix v2

       1
o66 = R

o66 : R-module, free

i67 : degree v1, degree v2

o67 = ({2}, {2})

o67 : Sequence

i68 : degree matrix v1, degree matrix v2

o68 = ({0}, {2})

o68 : Sequence

Somehow the vectors are the same, but the internal matrix representations have different degrees, which I think should be irrelevant (or rather, the internal matrix degree of vectors should be always set to zero).

pzinn commented 12 months ago

agreed. unrelated to my (now closed) issue though :-P