@@ -4845,11 +4845,23 @@ def intersection(self, other):
4845
4845
F = F + [s for s in self .faces ()[k ] if s in other .faces ()[k ]]
4846
4846
return SimplicialComplex (F )
4847
4847
4848
- def bigraded_betti_numbers (self , base_ring = ZZ ):
4848
+ def bigraded_betti_numbers (self , base_ring = ZZ , verbose = False ):
4849
4849
r"""
4850
4850
Return a dictionary of the bigraded Betti numbers of ``self``,
4851
4851
with keys `(-a, 2b)`.
4852
4852
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
+
4853
4865
.. SEEALSO::
4854
4866
4855
4867
See :meth:`bigraded_betti_number` for more information.
@@ -4858,12 +4870,56 @@ def bigraded_betti_numbers(self, base_ring=ZZ):
4858
4870
4859
4871
sage: X = SimplicialComplex([[0,1],[1,2],[1,3],[2,3]])
4860
4872
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)
4862
4874
[((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)
4864
4890
[((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 :
4867
4923
return self ._bbn [base_ring ]
4868
4924
4869
4925
from sage .homology .homology_group import HomologyGroup
@@ -4884,18 +4940,33 @@ def bigraded_betti_numbers(self, base_ring=ZZ):
4884
4940
if ind not in B :
4885
4941
B [ind ] = ZZ .zero ()
4886
4942
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 ))
4887
4945
4888
4946
self ._bbn [base_ring ] = B
4889
4947
self ._bbn_all_computed .add (base_ring )
4890
4948
4891
4949
return B
4892
4950
4893
- def bigraded_betti_number (self , a , b , base_ring = ZZ ):
4951
+ def bigraded_betti_number (self , a , b , base_ring = ZZ , verbose = False ):
4894
4952
r"""
4895
4953
Return the bigraded Betti number indexed in the form `(-a, 2b)`.
4896
4954
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.
4899
4970
4900
4971
EXAMPLES::
4901
4972
@@ -4915,12 +4986,21 @@ def bigraded_betti_number(self, a, b, base_ring=ZZ):
4915
4986
2
4916
4987
sage: X.bigraded_betti_number(-1, 8)
4917
4988
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
4918
4998
"""
4919
4999
if b % 2 :
4920
5000
return ZZ .zero ()
4921
5001
if a == 0 and b == 0 :
4922
5002
return ZZ .one ()
4923
- if base_ring in self ._bbn :
5003
+ if base_ring in self ._bbn and not verbose :
4924
5004
if base_ring in self ._bbn_all_computed :
4925
5005
return self ._bbn [base_ring ].get ((a , b ), ZZ .zero ())
4926
5006
elif (a , b ) in self ._bbn [base_ring ]:
@@ -4939,6 +5019,8 @@ def bigraded_betti_number(self, a, b, base_ring=ZZ):
4939
5019
H = S .homology (base_ring = base_ring )
4940
5020
if b + a - 1 in H and H [b + a - 1 ] != H0 :
4941
5021
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 ))
4942
5024
4943
5025
B = ZZ (B )
4944
5026
0 commit comments