From 146087011bdd6af8e9569ca9dd0f142f63713751 Mon Sep 17 00:00:00 2001 From: Mahrud Sayrafi Date: Thu, 5 Jun 2025 18:26:51 -0400 Subject: [PATCH] changed how complexes are checked to be identical internally --- .../packages/Complexes/ChainComplex.m2 | 8 +++++-- .../packages/Complexes/ChainComplexMap.m2 | 23 +++++++++++++------ .../packages/Complexes/ChainComplexTests.m2 | 10 ++++++++ 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/M2/Macaulay2/packages/Complexes/ChainComplex.m2 b/M2/Macaulay2/packages/Complexes/ChainComplex.m2 index 82a5b4595ef..5989e468490 100644 --- a/M2/Macaulay2/packages/Complexes/ChainComplex.m2 +++ b/M2/Macaulay2/packages/Complexes/ChainComplex.m2 @@ -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; diff --git a/M2/Macaulay2/packages/Complexes/ChainComplexMap.m2 b/M2/Macaulay2/packages/Complexes/ChainComplexMap.m2 index 08625c4a0dc..4ca93d1058c 100644 --- a/M2/Macaulay2/packages/Complexes/ChainComplexMap.m2 +++ b/M2/Macaulay2/packages/Complexes/ChainComplexMap.m2 @@ -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); @@ -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); @@ -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; @@ -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)) -------------------------------------------------------------------- @@ -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)) -------------------------------------------------------------------- @@ -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; diff --git a/M2/Macaulay2/packages/Complexes/ChainComplexTests.m2 b/M2/Macaulay2/packages/Complexes/ChainComplexTests.m2 index 484acfc3389..388aed68bd3 100644 --- a/M2/Macaulay2/packages/Complexes/ChainComplexTests.m2 +++ b/M2/Macaulay2/packages/Complexes/ChainComplexTests.m2 @@ -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 ///