Skip to content

Commit ce855de

Browse files
author
Release Manager
committed
gh-36166: Additions to the bigraded Betti number methods This pull request expands the functionality of ``bigraded_betti_number()`` methods of a ``SimplicialComplex`` by adding an additional parameter ``verbose``. The ``verbose`` option increases verbosity while computing the invariant by printing the subcomplexes along with their non-trivial homology groups. This PR is a part of #35640 (GSoC 2023). ### 📝 Checklist - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation accordingly. URL: #36166 Reported by: Ognjen Petrov Reviewer(s): Ognjen Petrov, Travis Scrimshaw
2 parents 05d7d1d + 037b616 commit ce855de

File tree

1 file changed

+91
-9
lines changed

1 file changed

+91
-9
lines changed

src/sage/topology/simplicial_complex.py

Lines changed: 91 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4845,11 +4845,23 @@ def intersection(self, other):
48454845
F = F + [s for s in self.faces()[k] if s in other.faces()[k]]
48464846
return SimplicialComplex(F)
48474847

4848-
def bigraded_betti_numbers(self, base_ring=ZZ):
4848+
def bigraded_betti_numbers(self, base_ring=ZZ, verbose=False):
48494849
r"""
48504850
Return a dictionary of the bigraded Betti numbers of ``self``,
48514851
with keys `(-a, 2b)`.
48524852
4853+
INPUT:
4854+
4855+
- ``base_ring`` -- (default: ``ZZ``) the base ring used
4856+
when computing homology
4857+
- ``verbose`` -- (default: ``False``) if ``True``, print
4858+
messages during the computation, which indicate in which
4859+
subcomplexes non-trivial homologies appear
4860+
4861+
.. NOTE::
4862+
4863+
If ``verbose`` is ``True``, then caching is avoided.
4864+
48534865
.. SEEALSO::
48544866
48554867
See :meth:`bigraded_betti_number` for more information.
@@ -4858,12 +4870,56 @@ def bigraded_betti_numbers(self, base_ring=ZZ):
48584870
48594871
sage: X = SimplicialComplex([[0,1],[1,2],[1,3],[2,3]])
48604872
sage: Y = SimplicialComplex([[1,2,3],[1,2,4],[3,5],[4,5]])
4861-
sage: sorted(X.bigraded_betti_numbers().items(), reverse=True) # needs sage.modules
4873+
sage: sorted(X.bigraded_betti_numbers(base_ring=QQ).items(), reverse=True)
48624874
[((0, 0), 1), ((-1, 6), 1), ((-1, 4), 2), ((-2, 8), 1), ((-2, 6), 1)]
4863-
sage: sorted(Y.bigraded_betti_numbers(base_ring=QQ).items(), reverse=True) # needs sage.modules
4875+
sage: sorted(Y.bigraded_betti_numbers(verbose=True).items(), reverse=True)
4876+
(-1, 4): Non-trivial homology Z in dimension 0 of the full
4877+
subcomplex generated by a set of vertices (1, 5)
4878+
(-1, 4): Non-trivial homology Z in dimension 0 of the full
4879+
subcomplex generated by a set of vertices (2, 5)
4880+
(-1, 4): Non-trivial homology Z in dimension 0 of the full
4881+
subcomplex generated by a set of vertices (3, 4)
4882+
(-2, 6): Non-trivial homology Z in dimension 0 of the full
4883+
subcomplex generated by a set of vertices (1, 2, 5)
4884+
(-2, 8): Non-trivial homology Z in dimension 1 of the full
4885+
subcomplex generated by a set of vertices (1, 3, 4, 5)
4886+
(-2, 8): Non-trivial homology Z in dimension 1 of the full
4887+
subcomplex generated by a set of vertices (2, 3, 4, 5)
4888+
(-3, 10): Non-trivial homology Z in dimension 1 of the full
4889+
subcomplex generated by a set of vertices (1, 2, 3, 4, 5)
48644890
[((0, 0), 1), ((-1, 4), 3), ((-2, 8), 2), ((-2, 6), 1), ((-3, 10), 1)]
4865-
"""
4866-
if base_ring in self._bbn_all_computed:
4891+
4892+
If we wish to view them in a form of a table, it is
4893+
simple enough to create a function as such::
4894+
4895+
sage: def print_table(bbns):
4896+
....: max_a = max(-p[0] for p in bbns)
4897+
....: max_b = max(p[1] for p in bbns)
4898+
....: bbn_table = [[bbns.get((-a,b), 0) for a in range(max_a+1)]
4899+
....: for b in range(max_b+1)]
4900+
....: width = len(str(max(bbns.values()))) + 1
4901+
....: print(' '*width, end=' ')
4902+
....: for i in range(max_a+1):
4903+
....: print(f'{-i:{width}}', end=' ')
4904+
....: print()
4905+
....: for j in range(len(bbn_table)):
4906+
....: print(f'{j:{width}}', end=' ')
4907+
....: for r in bbn_table[j]:
4908+
....: print(f'{r:{width}}', end=' ')
4909+
....: print()
4910+
sage: print_table(X.bigraded_betti_numbers())
4911+
0 -1 -2
4912+
0 1 0 0
4913+
1 0 0 0
4914+
2 0 0 0
4915+
3 0 0 0
4916+
4 0 2 0
4917+
5 0 0 0
4918+
6 0 1 1
4919+
7 0 0 0
4920+
8 0 0 1
4921+
"""
4922+
if base_ring in self._bbn_all_computed and not verbose:
48674923
return self._bbn[base_ring]
48684924

48694925
from sage.homology.homology_group import HomologyGroup
@@ -4884,18 +4940,33 @@ def bigraded_betti_numbers(self, base_ring=ZZ):
48844940
if ind not in B:
48854941
B[ind] = ZZ.zero()
48864942
B[ind] += len(H[j-k-1].gens())
4943+
if verbose:
4944+
print("{}: Non-trivial homology {} in dimension {} of the full subcomplex generated by a set of vertices {}".format(ind, H[j-k-1], j-k-1, x))
48874945

48884946
self._bbn[base_ring] = B
48894947
self._bbn_all_computed.add(base_ring)
48904948

48914949
return B
48924950

4893-
def bigraded_betti_number(self, a, b, base_ring=ZZ):
4951+
def bigraded_betti_number(self, a, b, base_ring=ZZ, verbose=False):
48944952
r"""
48954953
Return the bigraded Betti number indexed in the form `(-a, 2b)`.
48964954
4897-
Bigraded Betti number with indices `(-a, 2b)` is defined as a sum of ranks
4898-
of `(b-a-1)`-th (co)homologies of full subcomplexes with exactly `b` vertices.
4955+
Bigraded Betti number with indices `(-a, 2b)` is defined as a
4956+
sum of ranks of `(b-a-1)`-th (co)homologies of full subcomplexes
4957+
with exactly `b` vertices.
4958+
4959+
INPUT:
4960+
4961+
- ``base_ring`` -- (default: ``ZZ``) the base ring used
4962+
when computing homology
4963+
- ``verbose`` -- (default: ``False``) if ``True``, print
4964+
messages during the computation, which indicate in which
4965+
subcomplexes non-trivial homologies appear
4966+
4967+
.. NOTE::
4968+
4969+
If ``verbose`` is ``True``, then caching is avoided.
48994970
49004971
EXAMPLES::
49014972
@@ -4915,12 +4986,21 @@ def bigraded_betti_number(self, a, b, base_ring=ZZ):
49154986
2
49164987
sage: X.bigraded_betti_number(-1, 8)
49174988
0
4989+
sage: Y = SimplicialComplex([[1,2,3],[1,2,4],[3,5],[4,5]])
4990+
sage: Y.bigraded_betti_number(-1, 4, verbose=True)
4991+
Non-trivial homology Z in dimension 0 of the full subcomplex
4992+
generated by a set of vertices (1, 5)
4993+
Non-trivial homology Z in dimension 0 of the full subcomplex
4994+
generated by a set of vertices (2, 5)
4995+
Non-trivial homology Z in dimension 0 of the full subcomplex
4996+
generated by a set of vertices (3, 4)
4997+
3
49184998
"""
49194999
if b % 2:
49205000
return ZZ.zero()
49215001
if a == 0 and b == 0:
49225002
return ZZ.one()
4923-
if base_ring in self._bbn:
5003+
if base_ring in self._bbn and not verbose:
49245004
if base_ring in self._bbn_all_computed:
49255005
return self._bbn[base_ring].get((a, b), ZZ.zero())
49265006
elif (a, b) in self._bbn[base_ring]:
@@ -4939,6 +5019,8 @@ def bigraded_betti_number(self, a, b, base_ring=ZZ):
49395019
H = S.homology(base_ring=base_ring)
49405020
if b+a-1 in H and H[b+a-1] != H0:
49415021
B += len(H[b+a-1].gens())
5022+
if verbose:
5023+
print("Non-trivial homology {} in dimension {} of the full subcomplex generated by a set of vertices {}".format(H[b+a-1], b+a-1, x))
49425024

49435025
B = ZZ(B)
49445026

0 commit comments

Comments
 (0)