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

Adding bigraded Betti numbers functionality #35430

Merged
merged 47 commits into from
May 22, 2023
Merged
Changes from 44 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
f5069ae
Added bigraded_betti_number() functions
OP5642 Apr 1, 2023
300d722
Fixed bigraded_betti_number()
OP5642 Apr 3, 2023
55de294
Removed last (empty) line
OP5642 Apr 3, 2023
f3895ed
Fixed bigraded_betti_numbers() and minor changes to the documentation
OP5642 Apr 4, 2023
b46199c
Improved documentation and corrected examples
OP5642 Apr 4, 2023
d161061
Corrected code formatting
OP5642 Apr 4, 2023
3dd3ed3
Tried caching bigraded_betti_number()
OP5642 Apr 6, 2023
ac20f79
Update src/sage/topology/simplicial_complex.py
OP5642 Apr 7, 2023
8765c15
Update src/sage/topology/simplicial_complex.py
OP5642 Apr 7, 2023
03cf854
Update src/sage/topology/simplicial_complex.py
OP5642 Apr 7, 2023
785a9ba
Update src/sage/topology/simplicial_complex.py
OP5642 Apr 7, 2023
722381a
Improved checking if the homology is trivial in bigraded_betti_numbers()
OP5642 Apr 7, 2023
a665833
Update src/sage/topology/simplicial_complex.py
OP5642 Apr 8, 2023
853dd9a
Update src/sage/topology/simplicial_complex.py
OP5642 Apr 8, 2023
0087184
Update documentation for bigraded_betti_number()
OP5642 Apr 8, 2023
24434e9
Update documentation for bigraded_betti_number()
OP5642 Apr 8, 2023
3664220
Update src/sage/topology/simplicial_complex.py
OP5642 Apr 8, 2023
5058696
Update src/sage/topology/simplicial_complex.py
OP5642 Apr 8, 2023
794d7c6
Update src/sage/topology/simplicial_complex.py
OP5642 Apr 8, 2023
06a1a27
Update documentation for bigraded_betti_numbers()
OP5642 Apr 8, 2023
dbcbc02
Update src/sage/topology/simplicial_complex.py
OP5642 Apr 8, 2023
14b6f1c
Update src/sage/topology/simplicial_complex.py
OP5642 Apr 8, 2023
8154f79
Minor changes to bigraded_betti_number()
OP5642 Apr 8, 2023
859d9e4
Added bbn attribute
OP5642 Apr 8, 2023
177cbae
Added setting bbn attribute to add_face() and remove_face()
OP5642 Apr 9, 2023
fbc06be
Fixed typos and minor optimizations in bigraded_betti_number()
OP5642 Apr 11, 2023
0e6c016
Improved documentation and added a base ring parameter for bigraded_b…
OP5642 Apr 11, 2023
b656025
Fixed caching with different base rings for bigraded_betti_number()
OP5642 Apr 11, 2023
7f192f5
Improved caching for bigraded_betti_number()
OP5642 Apr 11, 2023
66bf431
Fixed caching in bigraded_betti_numbers()
OP5642 Apr 11, 2023
ee9c226
Fixed the ring of bigraded Betti numbers
OP5642 Apr 12, 2023
68da3fb
Minor changes to code formatting
OP5642 Apr 12, 2023
1135dce
Fixed caching for bigraded_betti_numbers()
OP5642 Apr 12, 2023
de1af92
Minor fixes in bigraded_betti_number()
OP5642 Apr 13, 2023
d79914a
Improved caching for bigraded_betti_numbers()
OP5642 Apr 13, 2023
9e974bc
Improved docstring of bigraded_betti_number() and reverted previous c…
OP5642 Apr 13, 2023
f3b6c04
Added comments
OP5642 Apr 14, 2023
f64a7f9
Improved docstring for bigraded_betti_number()
OP5642 Apr 14, 2023
794234d
Revert "Improved docstring for bigraded_betti_number()"
OP5642 Apr 14, 2023
1733b81
Improved docstring for bigraded_betti_number()
OP5642 Apr 14, 2023
d7c82bd
Improved caching for bigraded_betti_numbers()
OP5642 Apr 14, 2023
f8ce143
Fixed caching in bigraded_betti_number()
OP5642 Apr 14, 2023
6efeca8
Fixed initialization of bbn attributes
OP5642 Apr 14, 2023
157384a
Changed attribute name and fixed bigraded_betti_number()
OP5642 Apr 16, 2023
7ce7135
Removed trailing whitespaces
OP5642 Apr 19, 2023
3e03902
Corrected docstring for bigraded_betti_numbers()
OP5642 Apr 22, 2023
c669b5a
Fixed code formatting
OP5642 Apr 24, 2023
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
117 changes: 117 additions & 0 deletions src/sage/topology/simplicial_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,8 @@ def __init__(self,
self._is_immutable = False
if not is_mutable or is_immutable:
self.set_immutable()
self._bbn = C._bbn
self._bbn_all_computed = C._bbn_all_computed
return

gen_dict = {}
Expand Down Expand Up @@ -1126,6 +1128,14 @@ def __init__(self,
if not is_mutable or is_immutable:
self.set_immutable()

# self._bbn: a dictionary indexed by base_ring, whose value is a dictionary of
# bigraded Betti numbers, indexed by tuples (-i, 2j).
# For use in the bigraded_betti_numbers method.
self._bbn = {}
# self._bbn_all_computed: a set of base rings for which we called
# bigraded_betti_numbers(base_ring=base_ring)
self._bbn_all_computed = set()

def __hash__(self):
"""
Compute the hash value of ``self``.
Expand Down Expand Up @@ -2659,6 +2669,8 @@ def add_face(self, face):
self._graph.add_edge(new_face[i], new_face[j])
self._complex = {}
self.__contractible = None
self._bbn = {}
self._bbn_all_computed = set()

def remove_face(self, face, check=False):
"""
Expand Down Expand Up @@ -2783,6 +2795,8 @@ def remove_face(self, face, check=False):
self._complex = {}
self.__contractible = None
self.__enlarged = {}
self._bbn = {}
self._bbn_all_computed = set()

def remove_faces(self, faces, check=False):
"""
Expand Down Expand Up @@ -4802,7 +4816,110 @@ def intersection(self, other):
F = F + [s for s in self.faces()[k] if s in other.faces()[k]]
return SimplicialComplex(F)

def bigraded_betti_numbers(self, base_ring=ZZ):
r"""
Return a dictionary of the bigraded Betti numbers of ``self``,
with keys `(-a, 2b)`.

.. SEEALSO::

See :meth:`bigraded_betti_number` for more information.

EXAMPLES::

sage: X = SimplicialComplex([[0,1],[1,2],[1,3],[2,3]])
sage: Y = SimplicialComplex([[1,2,3],[1,2,4],[3,5],[4,5]])
sage: X.bigraded_betti_numbers()
{(0, 0): 1, (-1, 4): 2, (-1, 6): 1, (-2, 6): 1, (-2, 8): 1}
sage: Y.bigraded_betti_numbers(base_ring=QQ)
{(0, 0): 1, (-1, 4): 3, (-2, 6): 1, (-2, 8): 2, (-3, 10): 1}
"""
if base_ring in self._bbn_all_computed:
return self._bbn[base_ring]

from sage.homology.homology_group import HomologyGroup
L = self.vertices()
n = len(L)
B = {}
H0 = HomologyGroup(0, base_ring)

B[(0, 0)] = ZZ.one()

for j in range(n+1):
for x in combinations(L, j):
S = self.generated_subcomplex(x)
H = S.homology(base_ring=base_ring)
for k in range(j):
if j-k-1 in H and H[j-k-1] != H0:
ind = (-k, 2*j)
if ind not in B:
B[ind] = ZZ.zero()
B[ind] += len(H[j-k-1].gens())

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

return B

def bigraded_betti_number(self, a, b, base_ring=ZZ):
r"""
Return the bigraded Betti number indexed in the form `(-a, 2b)`.

Bigraded Betti number with indices `(-a, 2b)` is defined as a sum of ranks
of `(b-a-1)`-th (co)homologies of full subcomplexes with exactly `b` vertices.

EXAMPLES::

sage: X = SimplicialComplex([[0,1],[1,2],[2,0],[1,3]])
sage: X.bigraded_betti_number(-1, 4, base_ring=QQ)
2
sage: X.bigraded_betti_number(-1, 8)
0
sage: X.bigraded_betti_number(-2, 5)
0
sage: X.bigraded_betti_number(0, 0)
1
sage: X.bigraded_betti_numbers()
{(0, 0): 1, (-1, 4): 2, (-1, 6): 1, (-2, 6): 1, (-2, 8): 1}
sage: X.bigraded_betti_number(-1, 4, base_ring=QQ)
2
sage: X.bigraded_betti_number(-1, 8)
0
"""
if b % 2:
return ZZ.zero()
if a == 0 and b == 0:
return ZZ.one()
if base_ring in self._bbn:
if base_ring in self._bbn_all_computed:
return self._bbn[base_ring].get((a,b), ZZ.zero())
elif (a, b) in self._bbn[base_ring]:
return self._bbn[base_ring][a, b]

from sage.homology.homology_group import HomologyGroup

b //= 2
L = self.vertices()
n = len(L)
H0 = HomologyGroup(0, base_ring)

B = 0

for x in combinations(L, b):
S = self.generated_subcomplex(x)
H = S.homology(base_ring=base_ring)
if b+a-1 in H and H[b+a-1] != H0:
B += len(H[b+a-1].gens())

B = ZZ(B)

if base_ring in self._bbn:
self._bbn[base_ring][(a, 2*b)] = B
else:
self._bbn[base_ring] = {(a, 2*b): B}

return B
OP5642 marked this conversation as resolved.
Show resolved Hide resolved

# Miscellaneous utility functions.

# The following two functions can be used to generate the facets for
Expand Down