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 7 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
88 changes: 88 additions & 0 deletions src/sage/topology/simplicial_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -4802,7 +4802,95 @@ def intersection(self, other):
F = F + [s for s in self.faces()[k] if s in other.faces()[k]]
return SimplicialComplex(F)

#@cached_method tried this, but does not make much sense to cache this
def bigraded_betti_numbers(self):
r"""
Returns a dictionary of the bigraded Betti numbers of ''self'',
with keys '(-i, 2j)'.

See bigraded_betti_number(self, a, b) for more information.
OP5642 marked this conversation as resolved.
Show resolved Hide resolved

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()
{(0, 0): 1, (-1,4 ): 3, (-2, 6): 1, (-2, 8): 2, (-3, 10): 1}
"""
from sage.misc.functional import gens
L = set(self.vertices())
OP5642 marked this conversation as resolved.
Show resolved Hide resolved
n = len(L)
D = {}
B = {}
Point = SimplicialComplex([[0]])
H0 = Point.homology().get(0)

for i in range(n+1):
D[i] = list(combinations(L,i))

for i in range(n+1):
for j in range (n+1):
B[(-i, 2*j)] = self.bigraded_betti_number(-i, 2*j)

#B[(0,0)] = 1

#for j in range(n+1):
#for x in D[j]:
#S = self.generated_subcomplex(x)
#H = S.homology()
#for k in range(j):
#if H.get(j-k-1) != H0 and H.get(j-k-1) != None:
#B[(-k, 2*j)] = B[(-k, 2*j)] + len(gens(H.get(j-k-1)))

B = {key:val for key,val in B.items() if val != 0}
OP5642 marked this conversation as resolved.
Show resolved Hide resolved

return B

@cached_method
def bigraded_betti_number(self, a, b):
r"""
Returns the bigraded Betti number indexed in the form (-i, 2j).
OP5642 marked this conversation as resolved.
Show resolved Hide resolved

Bigraded Betti number with indices '(-i, 2j)' is defined as a sum of ranks
of '(i-j-1)'-th (co)homologies of full subcomplexes with exactly 'j' vertices.
OP5642 marked this conversation as resolved.
Show resolved Hide resolved

EXAMPLES::

sage: X = SimplicialComplex([[0,1],[1,2],[2,0],[1,2,3]])
sage: X.bigraded_betti_numbers()
{(0, 0): 1, ,(-1,4): 1, (-1, 6): 1, (-2, 8): 1}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{(0, 0): 1, ,(-1,4): 1, (-1, 6): 1, (-2, 8): 1}
{(0, 0): 1, (-1,4): 1, (-1, 6): 1, (-2, 8): 1}

I think there is a typo here.

Can you also add a test checking the different cases:

  1. the (0, 0) input;
  2. an (a, 2b) entry that is zero;
  3. for (a, 2b+1);
  4. The same tests but before setting the cache (see also the comment below).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for noticing. I will add those tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be appropriate now, if I understood you correctly.

sage: X.bigraded_betti_number(-1, 6)
1
"""
from sage.misc.functional import gens
OP5642 marked this conversation as resolved.
Show resolved Hide resolved
if b % 2 == 1:
return 'Error: Second argument must be even.'
OP5642 marked this conversation as resolved.
Show resolved Hide resolved
if a == 0 and b == 0:
return 1;
OP5642 marked this conversation as resolved.
Show resolved Hide resolved

a = -a
OP5642 marked this conversation as resolved.
Show resolved Hide resolved
b = b / 2
OP5642 marked this conversation as resolved.
Show resolved Hide resolved
L = set(self.vertices())
OP5642 marked this conversation as resolved.
Show resolved Hide resolved
n = len(L)
D = {}
Point = SimplicialComplex([[0]])
H0 = Point.homology().get(0)

for i in range(n + 1):
D[i] = list(combinations(L, i))

B = 0

for x in D[b]:
OP5642 marked this conversation as resolved.
Show resolved Hide resolved
S = self.generated_subcomplex(x)
H = S.homology()
if H.get(b-a-1) != H0 and H.get(b-a-1) != None:
OP5642 marked this conversation as resolved.
Show resolved Hide resolved
B = B + len(gens(H.get(b-a-1)))

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