Skip to content

Commit e129160

Browse files
committed
Initial additions
1 parent 4d3e807 commit e129160

File tree

1 file changed

+64
-7
lines changed

1 file changed

+64
-7
lines changed

src/sage/topology/simplicial_complex.py

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4845,11 +4845,19 @@ 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`` -- (optional, default ``ZZ``) the base ring used
4856+
when computing homology
4857+
- ``verbose`` -- (optional, default ``False``) if ``True``, print
4858+
messages during the computation, which indicate in which subcomplexes
4859+
non-trivial homologies appear
4860+
48534861
.. SEEALSO::
48544862
48554863
See :meth:`bigraded_betti_number` for more information.
@@ -4862,8 +4870,38 @@ def bigraded_betti_numbers(self, base_ring=ZZ):
48624870
[((0, 0), 1), ((-1, 6), 1), ((-1, 4), 2), ((-2, 8), 1), ((-2, 6), 1)]
48634871
sage: sorted(Y.bigraded_betti_numbers(base_ring=QQ).items(), reverse=True) # needs sage.modules
48644872
[((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:
4873+
4874+
If we wish to view them in a form of a table, it is
4875+
simple enough to create a function as such::
4876+
4877+
sage: def print_table(bbns):
4878+
....: max_a = max(-p[0] for p in bbns)
4879+
....: max_b = max(p[1] for p in bbns)
4880+
....: bbn_table = [[bbns.get((-a,b), 0) for a in range(max_a+1)]
4881+
....: for b in range(max_b+1)]
4882+
....: width = len(str(max(bbns.values()))) + 1
4883+
....: print(' '*width, end=' ')
4884+
....: for i in range(max_a+1):
4885+
....: print(f'{-i:{width}}', end=' ')
4886+
....: print()
4887+
....: for j in range(len(bbn_table)):
4888+
....: print(f'{j:{width}}', end=' ')
4889+
....: for r in bbn_table[j]:
4890+
....: print(f'{r:{width}}', end=' ')
4891+
....: print()
4892+
sage: print_table(X.bigraded_betti_numbers())
4893+
0 -1 -2
4894+
0 1 0 0
4895+
1 0 0 0
4896+
2 0 0 0
4897+
3 0 0 0
4898+
4 0 2 0
4899+
5 0 0 0
4900+
6 0 1 1
4901+
7 0 0 0
4902+
8 0 0 1
4903+
"""
4904+
if base_ring in self._bbn_all_computed and not verbose:
48674905
return self._bbn[base_ring]
48684906

48694907
from sage.homology.homology_group import HomologyGroup
@@ -4884,18 +4922,29 @@ def bigraded_betti_numbers(self, base_ring=ZZ):
48844922
if ind not in B:
48854923
B[ind] = ZZ.zero()
48864924
B[ind] += len(H[j-k-1].gens())
4925+
if verbose:
4926+
print("Non-trivial homology {} in dimension {} of the full subcomplex generated by a set of vertices {}".format(H[j-k-1], j-k-1, x))
48874927

48884928
self._bbn[base_ring] = B
48894929
self._bbn_all_computed.add(base_ring)
48904930

48914931
return B
48924932

4893-
def bigraded_betti_number(self, a, b, base_ring=ZZ):
4933+
def bigraded_betti_number(self, a, b, base_ring=ZZ, verbose=False):
48944934
r"""
48954935
Return the bigraded Betti number indexed in the form `(-a, 2b)`.
48964936
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.
4937+
Bigraded Betti number with indices `(-a, 2b)` is defined as a
4938+
sum of ranks of `(b-a-1)`-th (co)homologies of full subcomplexes
4939+
with exactly `b` vertices.
4940+
4941+
INPUT:
4942+
4943+
- ``base_ring`` -- (optional, default ``ZZ``) the base ring used
4944+
when computing homology
4945+
- ``verbose`` -- (optional, default ``False``) if ``True``, print
4946+
messages during the computation, which indicate in which subcomplexes
4947+
non-trivial homologies appear
48994948
49004949
EXAMPLES::
49014950
@@ -4915,12 +4964,18 @@ def bigraded_betti_number(self, a, b, base_ring=ZZ):
49154964
2
49164965
sage: X.bigraded_betti_number(-1, 8)
49174966
0
4967+
sage: Y = SimplicialComplex([[1,2,3],[1,2,4],[3,5],[4,5]])
4968+
sage: Y.bigraded_betti_number(-1, 4, verbose=True)
4969+
Non-trivial homology Z in dimension 0 of the full subcomplex generated by a set of vertices (1, 5)
4970+
Non-trivial homology Z in dimension 0 of the full subcomplex generated by a set of vertices (2, 5)
4971+
Non-trivial homology Z in dimension 0 of the full subcomplex generated by a set of vertices (3, 4)
4972+
3
49184973
"""
49194974
if b % 2:
49204975
return ZZ.zero()
49214976
if a == 0 and b == 0:
49224977
return ZZ.one()
4923-
if base_ring in self._bbn:
4978+
if base_ring in self._bbn and not verbose:
49244979
if base_ring in self._bbn_all_computed:
49254980
return self._bbn[base_ring].get((a, b), ZZ.zero())
49264981
elif (a, b) in self._bbn[base_ring]:
@@ -4939,6 +4994,8 @@ def bigraded_betti_number(self, a, b, base_ring=ZZ):
49394994
H = S.homology(base_ring=base_ring)
49404995
if b+a-1 in H and H[b+a-1] != H0:
49414996
B += len(H[b+a-1].gens())
4997+
if verbose:
4998+
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))
49424999

49435000
B = ZZ(B)
49445001

0 commit comments

Comments
 (0)