Skip to content
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

Fix bug caused by cached representation in cohomology classes #35650

Merged
merged 4 commits into from
Jun 3, 2023
Merged
Changes from 1 commit
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
53 changes: 49 additions & 4 deletions src/sage/algebras/commutative_dga.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ def cohomology(self, n):
H_basis = [sum(c * b for (c, b) in zip(coeffs, B)) for coeffs in
H_basis_raw]
# Put brackets around classes.
H_basis_brackets = [CohomologyClass(b) for b in H_basis]
H_basis_brackets = [CohomologyClass(b, A) for b in H_basis]
return CombinatorialFreeModule(A.base_ring(),
H_basis_brackets,
sorting_key=sorting_keys,
Expand Down Expand Up @@ -855,7 +855,7 @@ def cohomology(self, n, total=False):
H_basis = [sum(c * b for (c, b) in zip(coeffs, B))
for coeffs in H_basis_raw]
# Put brackets around classes.
H_basis_brackets = [CohomologyClass(b) for b in H_basis]
H_basis_brackets = [CohomologyClass(b, A) for b in H_basis]
return CombinatorialFreeModule(A.base_ring(),
H_basis_brackets,
sorting_key=sorting_keys,
Expand Down Expand Up @@ -3893,10 +3893,54 @@ class CohomologyClass(SageObject, CachedRepresentation):
sage: CohomologyClass(3)
[3]
sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees = (2,2,3,3))
sage: CohomologyClass(x^2+2*y*z)
sage: CohomologyClass(x^2+2*y*z, A)
[2*y*z + x^2]

In order for the cache to not confuse objects with the same representation,
we can pass a parent as a parameter.

TESTS::

sage: A.<e1,e2,e3,e4,e5,e6> = GradedCommutativeAlgebra(QQ)
sage: B1 = A.cdg_algebra({e5:e1*e2,e6:e3*e4})
sage: B2 = A.cdg_algebra({e5:e1*e2,e6:e1*e2+e3*e4})
sage: B1.minimal_model()
Commutative Differential Graded Algebra morphism:
From: Commutative Differential Graded Algebra with generators ('x1_0', 'x1_1', 'x1_2', 'x1_3', 'y1_0', 'y1_1') in degrees (1, 1, 1, 1, 1, 1) over Rational Field with differential:
x1_0 --> 0
x1_1 --> 0
x1_2 --> 0
x1_3 --> 0
y1_0 --> x1_0*x1_1
y1_1 --> x1_2*x1_3
To: Commutative Differential Graded Algebra with generators ('e1', 'e2', 'e3', 'e4', 'e5', 'e6') in degrees (1, 1, 1, 1, 1, 1) over Rational Field with differential:
e1 --> 0
e2 --> 0
e3 --> 0
e4 --> 0
e5 --> e1*e2
e6 --> e3*e4
Defn: (x1_0, x1_1, x1_2, x1_3, y1_0, y1_1) --> (e1, e2, e3, e4, e5, e6)
sage: B2.minimal_model()
Commutative Differential Graded Algebra morphism:
From: Commutative Differential Graded Algebra with generators ('x1_0', 'x1_1', 'x1_2', 'x1_3', 'y1_0', 'y1_1') in degrees (1, 1, 1, 1, 1, 1) over Rational Field with differential:
x1_0 --> 0
x1_1 --> 0
x1_2 --> 0
x1_3 --> 0
y1_0 --> x1_0*x1_1
y1_1 --> x1_2*x1_3
To: Commutative Differential Graded Algebra with generators ('e1', 'e2', 'e3', 'e4', 'e5', 'e6') in degrees (1, 1, 1, 1, 1, 1) over Rational Field with differential:
e1 --> 0
e2 --> 0
e3 --> 0
e4 --> 0
e5 --> e1*e2
e6 --> e1*e2 + e3*e4
Defn: (x1_0, x1_1, x1_2, x1_3, y1_0, y1_1) --> (e1, e2, e3, e4, e5, -e5 + e6)

"""
def __init__(self, x):
def __init__(self, x, parent = None):
mkoeppe marked this conversation as resolved.
Show resolved Hide resolved
"""
EXAMPLES::

Expand All @@ -3905,6 +3949,7 @@ def __init__(self, x):
[x - 2]
"""
self._x = x
self._par = parent

def __hash__(self):
r"""
Expand Down