Skip to content

Changed Complex strict equality internally #3874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions M2/Macaulay2/packages/Complexes/ChainComplex.m2
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,12 @@ length Complex := (C) -> (
hi-lo
)

Complex == Complex := (C,D) -> (
if C === D then return true;
-- this method is not exported, and is only used internally instead of === and =!=,
-- since Complex is a MutableHashTable and are never identical unless literally the same.
isIdentical = method()
isIdentical(Complex, Complex) := (C, D) -> C === D or C.module === D.module and C.dd.map === D.dd.map

Complex == Complex := (C,D) -> isIdentical(C, D) or (
(loC,hiC) := C.concentration;
(loD,hiD) := D.concentration;
if ring C =!= ring D then return false;
Expand Down
23 changes: 16 additions & 7 deletions M2/Macaulay2/packages/Complexes/ChainComplexMap.m2
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ map(Complex, Complex, ComplexMap) := ComplexMap => opts -> (tar, src, f) -> (
)

ComplexMap | ComplexMap := ComplexMap => (f,g) -> (
if target f =!= target g then error "expected targets to be the same";
if not isIdentical(target f, target g) then error "expected targets to be the same";
deg := degree f;
if deg =!= degree g then error "expected maps with the same degree";
result := map(target f, source f ++ source g, {{f,g}}, Degree=>deg);
Expand All @@ -121,7 +121,7 @@ ComplexMap | ComplexMap := ComplexMap => (f,g) -> (
)

ComplexMap || ComplexMap := ComplexMap => (f,g) -> (
if source f =!= source g then error "expected sources to be the same";
if not isIdentical(source f, source g) then error "expected sources to be the same";
deg := degree f;
if deg =!= degree g then error "expected maps with the same degree";
result := map(target f ++ target g, source f, {{f},{g}}, Degree=>deg);
Expand Down Expand Up @@ -277,8 +277,14 @@ ComplexMap ^ ZZ := ComplexMap => (f,n) -> (
)
)

ComplexMap == ComplexMap := (f,g) -> (
if f === g then return true;
-- this method is not exported, and is only
-- used internally instead of === and =!=
isIdentical(ComplexMap, ComplexMap) := (f, g) -> f === g or (
f.degree === g.degree and f.map === g.map
and isIdentical(f.source, g.source)
and isIdentical(f.target, g.target))

ComplexMap == ComplexMap := (f,g) -> isIdentical(f, g) or (
if source f != source g or target f != target g
then return false;
(lo1,hi1) := (source f).concentration;
Expand Down Expand Up @@ -524,7 +530,8 @@ truncate(ZZ, ComplexMap) :=
truncate(List, ComplexMap) := ComplexMap => truncateMatrixOpts >> opts -> (degs, f) -> (
d := degree f;
C := truncate(degs, source f, opts);
D := if source f === target f then C else truncate(degs, target f, opts);
D := if isIdentical(source f, target f) then C
else truncate(degs, target f, opts);
map(D, C, i -> inducedTruncationMap(D_(i+d), C_i, f_i), Degree => d))

--------------------------------------------------------------------
Expand All @@ -538,7 +545,8 @@ basis(ZZ, ComplexMap) :=
basis(List, ComplexMap) := ComplexMap => opts -> (deg, f) -> (
d := degree f;
C := basis(deg, source f, opts);
D := if source f === target f then C else basis(deg, target f, opts);
D := if isIdentical(source f, target f) then C
else basis(deg, target f, opts);
map(D, C, i -> inducedBasisMap(D_(i+d), C_i, f_i), Degree => d))

--------------------------------------------------------------------
Expand Down Expand Up @@ -1276,7 +1284,8 @@ liftMapAlongQuasiIsomorphism(ComplexMap, ComplexMap) := (alpha,beta) -> (
P := source alpha;
N := target alpha;
M := source beta;
if N =!= target beta then error "expected targets of two maps to be the same complex";
if not isIdentical(N, target beta)
then error "expected targets of two maps to be the same complex";
(loP, hiP) := concentration P;
Cbeta := cone beta;
gamma := new MutableHashTable;
Expand Down
10 changes: 10 additions & 0 deletions M2/Macaulay2/packages/Complexes/ChainComplexTests.m2
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,16 @@ TEST ///
assert isWellDefined C
assert(HH C != complex coker f0)
assert(prune HH C == complex coker f0)

C = complex R
D = complex R
assert(C == D)
assert(C =!= D)
-- these operations didn't work before isIdentical
-- was used internally instead of === and =!=
id_C | id_D
id_C || id_D
id_C // id_D
///

TEST ///
Expand Down
Loading