Skip to content

Commit ff51547

Browse files
author
Release Manager
committed
sagemathgh-37132: Fix corners cases of free resolutions <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes sagemath#1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> as seen in ```sage sage: P2.<x,y,z> = ProjectiveSpace(QQ, 2) sage: S = P2.coordinate_ring() sage: I = S.ideal(0) sage: C = I.graded_free_resolution(); C S(0) <-- 0 sage: C[1] Ambient free module of rank 0 over the integral domain Multivariate Polynomial Ring in x, y, z over Rational Field sage: C[0] ------------------------------------------------------------------------ --- IndexError Traceback (most recent call last) Cell In[5], line 1 ----> 1 C[Integer(0)] File ~/GitHub/sage/src/sage/homology/free_resolution.py:426, in FiniteFreeResolution.__getitem__(self, i) 424 F = FreeModule(self._base_ring, 0) 425 elif i == self._length: --> 426 F = FreeModule(self._base_ring, self._maps[i - 1].ncols()) 427 else: 428 F = FreeModule(self._base_ring, self._maps[i].nrows()) IndexError: list index out of range sage: C.differential(1) ------------------------------------------------------------------------ --- IndexError Traceback (most recent call last) Cell In[6], line 1 ----> 1 C.differential(Integer(1)) File ~/GitHub/sage/src/sage/homology/free_resolution.py:489, in FiniteFreeResolution.differential(self, i) 487 elif i == self._length + 1: 488 s = FreeModule(self._base_ring, 0) --> 489 t = FreeModule(self._base_ring, self._maps[i - 2].ncols()) 490 m = s.hom(0, t) 491 elif i > self._length + 1: IndexError: list index out of range ``` <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes sagemath#12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - sagemath#12345: short description why this is a dependency - sagemath#34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: sagemath#37132 Reported by: Kwankyu Lee Reviewer(s): Travis Scrimshaw
2 parents ac405d3 + 162163c commit ff51547

File tree

1 file changed

+54
-12
lines changed

1 file changed

+54
-12
lines changed

src/sage/homology/free_resolution.py

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
.. MATH::
99
10-
R^{n_1} \xleftarrow{d_1} R^{n_1} \xleftarrow{d_2}
10+
R^{n_0} \xleftarrow{d_1} R^{n_1} \xleftarrow{d_2}
1111
\cdots \xleftarrow{d_k} R^{n_k} \xleftarrow{d_{k+1}} 0
1212
1313
terminating with a zero module at the end that is exact (all homology groups
@@ -242,9 +242,20 @@ def _repr_module(self, i):
242242
'S^2'
243243
sage: r # indirect doctest
244244
S^1 <-- S^3 <-- S^2 <-- 0
245+
246+
TESTS::
247+
248+
sage: S.<x,y,z> = PolynomialRing(QQ)
249+
sage: I = S.ideal(0)
250+
sage: C = I.free_resolution()
251+
sage: C
252+
S^1 <-- 0
245253
"""
246254
if i == 0:
247-
r = self._maps[0].nrows()
255+
if self._length > 0:
256+
r = self._maps[0].nrows()
257+
else:
258+
r = self._initial_differential.domain().dimension()
248259
s = f'{self._name}^{r}'
249260
return s
250261
elif i > self._length:
@@ -422,6 +433,8 @@ def __getitem__(self, i):
422433
raise IndexError('invalid index')
423434
elif i > self._length:
424435
F = FreeModule(self._base_ring, 0)
436+
elif i == 0:
437+
F = self.differential(0).domain()
425438
elif i == self._length:
426439
F = FreeModule(self._base_ring, self._maps[i - 1].ncols())
427440
else:
@@ -444,11 +457,12 @@ def differential(self, i):
444457
sage: r
445458
S(0) <-- S(-2)⊕S(-2)⊕S(-2) <-- S(-3)⊕S(-3) <-- 0
446459
sage: r.differential(3)
447-
Free module morphism defined by the matrix []
448-
Domain: Ambient free module of rank 0 over the integral domain
449-
Multivariate Polynomial Ring in x, y, z, w over Rational Field
450-
Codomain: Ambient free module of rank 2 over the integral domain
451-
Multivariate Polynomial Ring in x, y, z, w over Rational Field
460+
Free module morphism defined as left-multiplication by the matrix
461+
[]
462+
Domain: Ambient free module of rank 0 over the integral domain
463+
Multivariate Polynomial Ring in x, y, z, w over Rational Field
464+
Codomain: Ambient free module of rank 2 over the integral domain
465+
Multivariate Polynomial Ring in x, y, z, w over Rational Field
452466
sage: r.differential(2)
453467
Free module morphism defined as left-multiplication by the matrix
454468
[-y x]
@@ -476,6 +490,31 @@ def differential(self, i):
476490
[-z^2 + y*w]
477491
[ y*z - x*w]
478492
[-y^2 + x*z]
493+
494+
TESTS::
495+
496+
sage: P2.<x,y,z> = ProjectiveSpace(QQ, 2)
497+
sage: S = P2.coordinate_ring()
498+
sage: I = S.ideal(0)
499+
sage: C = I.graded_free_resolution(); C
500+
S(0) <-- 0
501+
sage: C[1]
502+
Ambient free module of rank 0 over the integral domain
503+
Multivariate Polynomial Ring in x, y, z over Rational Field
504+
sage: C[0]
505+
Ambient free module of rank 1 over the integral domain
506+
Multivariate Polynomial Ring in x, y, z over Rational Field
507+
sage: C.differential(1)
508+
Free module morphism defined as left-multiplication by the matrix
509+
[]
510+
Domain: Ambient free module of rank 0 over the integral domain
511+
Multivariate Polynomial Ring in x, y, z over Rational Field
512+
Codomain: Ambient free module of rank 1 over the integral domain
513+
Multivariate Polynomial Ring in x, y, z over Rational Field
514+
sage: C.differential(1).matrix()
515+
[]
516+
sage: C.differential(1).matrix().dimensions()
517+
(1, 0)
479518
"""
480519
if i < 0:
481520
raise IndexError('invalid index')
@@ -484,14 +523,17 @@ def differential(self, i):
484523
return self._initial_differential
485524
except AttributeError:
486525
raise ValueError('0th differential map undefined')
487-
elif i == self._length + 1:
488-
s = FreeModule(self._base_ring, 0)
489-
t = FreeModule(self._base_ring, self._maps[i - 2].ncols())
490-
m = s.hom(0, t)
491526
elif i > self._length + 1:
492527
s = FreeModule(self._base_ring, 0)
493528
t = FreeModule(self._base_ring, 0)
494-
m = s.hom(0, t)
529+
m = s.hom(0, t, side='right')
530+
elif i == self._length + 1:
531+
s = FreeModule(self._base_ring, 0)
532+
if self._length > 0:
533+
t = FreeModule(self._base_ring, self._maps[i - 2].ncols())
534+
else:
535+
t = self._initial_differential.domain()
536+
m = s.hom(0, t, side='right')
495537
else:
496538
s = FreeModule(self._base_ring, self._maps[i - 1].ncols())
497539
t = FreeModule(self._base_ring, self._maps[i - 1].nrows())

0 commit comments

Comments
 (0)