Ask Your Question
0

Bug report: non-unit differential yields wrong homology when using generators=True and base_ring=QQ

asked 2025-07-16 17:22:29 +0200

stp gravatar image

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:

  1. Use SageMath version: 10.6 (Tested on SageMath 10.6, released 2024-03-31)
  2. 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.

edit retag flag offensive close merge delete

Comments

Max Alekseyev gravatar imageMax Alekseyev ( 2025-07-17 05:02:54 +0200 )edit
1
John Palmieri gravatar imageJohn Palmieri ( 2025-07-23 23:46:31 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2025-07-23 04:01:38 +0200

I think the problem is the line https://github.com/sagemath/sage/blob...: it checks whether an entry in a matrix is 1, whereas it should perhaps check that the entry is a unit.

edit flag offensive delete link more

Comments

Thank you very much for your help and for the quick response.

I followed your suggestion and modified the code, and the problem has been resolved. Your diagnosis was exactly right.

I greatly appreciate your assistance.

stp gravatar imagestp ( 2025-07-28 09:23:00 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2025-07-16 17:22:29 +0200

Seen: 140 times

Last updated: Jul 23