I've encountered an unexpected behavior when computing homology of a ChainComplex with base_ring=QQ
(Rational Field) where the differential matrix is 1x1 and its coefficient is a non-unit (i.e., not 0 or 1), specifically when generators=True
is set.
Problem Description:
When base_ring=QQ
and a differential matrix has a coefficient other than 0 or 1 (e.g., -1
, 2
, 1/2
), ChainComplex.homology(generators=True)
returns a non-zero dimensional homology group. This happens even though the generators=False
option correctly computes a zero-dimensional group, which is the mathematically expected result. This issue does not occur if base_ring=ZZ
(Integer Ring) is used for the same differential matrices. It seems the problem is related to base_ring=QQ
combined with generators=True
for any non-zero, non-unit coefficient in the differential.
Expected Mathematical Behavior:
For a trivial chain complex with a single 1x1 differential matrix d_1 = [[c]]
where c
is a non-zero constant, the map should be an isomorphism. Consequently, this results in a 0-dimensional homology group at all degrees. This holds true regardless of whether c
is 1, -1, 2, 1/2, etc., when working over a field like QQ.
Steps to Reproduce:
- Use SageMath version: 10.6 (Tested on SageMath 10.6, released 2024-03-31)
- Run the following SageMath code:
```python
from sage.all import *
# Coefficients to test (1, -1, 2, 1/2)
test_coefficients = [1, -1, 2, QQ(1)/2]
print("--- Testing with QQ (Rational Field) base_ring ---")
for coeff in test_coefficients:
differentials_QQ = {1: matrix(QQ, 1, 1, [[coeff]])}
chains_QQ = ChainComplex(differentials_QQ, base_ring=QQ, degree=-1)
homology_QQ_gens = chains_QQ.homology(generators=True)
homology_QQ_nogens = chains_QQ.homology(generators=False)
print(f"\nCoefficient: {coeff}")
print(f"Homology (generators=True): {homology_QQ_gens}")
print(f"Homology (generators=False): {homology_QQ_nogens}")
print("\n" + "=" * 50 + "\n")
print("--- Testing with ZZ (Integer Ring) base_ring (for comparison) ---")
for coeff_zz_val in [1, -1, 2]:
BaseRing_ZZ = ZZ
differentials_ZZ = {1: matrix(BaseRing_ZZ, 1, 1, [[coeff_zz_val]])}
chains_ZZ = ChainComplex(differentials_ZZ, base_ring=BaseRing_ZZ, degree=-1)
homology_ZZ_gens = chains_ZZ.homology(generators=True)
homology_ZZ_nogens = chains_ZZ.homology(generators=False)
print(f"\nCoefficient: {coeff_zz_val}")
print(f"Homology (generators=True): {homology_ZZ_gens}")
print(f"Homology (generators=False): {homology_ZZ_nogens}")
```
Expected Output for QQ (Rational Field):
For all coeff
values (1, -1, 2, 1/2), the homology group at degree 1 should be 0-dimensional, regardless of the generators
parameter.
Example: Homology (generators=True): {0: Vector space of dimension 0 over Rational Field, 1: Vector space of dimension 0 over Rational Field}
Actual Output (from SageMath 10.6):
--- Testing with QQ (Rational Field) base_ring ---
Coefficient: 1 Homology (generators=True): {0: [], 1: []} Homology (generators=False): {0: Vector space of dimension 0 over Rational Field, 1: Vector space of dimension 0 over Rational Field}
Coefficient: -1 Homology (generators=True): {0: [(Vector space of dimension 1 over Rational Field, Chain(0:(1)))], 1: []} Homology (generators=False): {0: Vector space of dimension 0 over Rational Field, 1: Vector space of dimension 0 over Rational Field}
Coefficient: 2 Homology (generators=True): {0: [(Vector space of dimension 1 over Rational Field, Chain(0:(1)))], 1: []} Homology (generators=False): {0: Vector space of dimension 0 over Rational Field, 1: Vector space of dimension 0 over Rational Field}
Coefficient: 0.5 Homology (generators=True): {0: [(Vector space of dimension 1 over Rational Field, Chain(0:(1)))], 1: []} Homology (generators=False): {0: Vector space of dimension 0 over Rational Field, 1: Vector space of dimension 0 over Rational Field}
==================================================
--- Testing with ZZ (Integer Ring) base_ring (for comparison) ---
Coefficient: 1 Homology (generators=True): {0: [], 1: []} Homology (generators=False): {0: 0, 1: 0}
Coefficient: -1 Homology (generators=True): {0: [], 1: []} Homology (generators=False): {0: 0, 1: 0}
This suggests a potential bug in how ChainComplex.homology()
constructs generators when the base ring is QQ
and differential coefficients are non-unit and non-zero.
Thank you for your time and assistance.