ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 04 Jul 2013 04:54:17 +0200homology of simplicial complexeshttps://ask.sagemath.org/question/9943/homology-of-simplicial-complexes/I am building a simplicial complex as follows:
sage: S = range(1,7)
sage: Z = SimplicialComplex([S])
sage: T = Z.n_skeleton(1)
sage: T.faces()
{0: set([(4,), (5,), (3,), (1,), (6,), (2,)]), 1: set([(2, 4), (3, 6),
(5, 6), (2, 6), (1, 4), (3, 5), (3, 4), (2, 3), (4, 6), (2, 5), (1, 2),
(1, 3), (4, 5), (1, 5), (1, 6)]), -1: set([()])}
sage: T.homology()
{0: 0, 1: Z^10}
So far everything seems good. Then I try adding a face to T.
sage: T.add_face([1,2,6])
sage: T.faces()
{0: set([(4,), (5,), (3,), (1,), (6,), (2,)]), 1: set([(2, 4), (3, 6),
(5, 6), (1, 5), (1, 4), (3, 5), (3, 4), (2, 3), (4, 6), (2, 5), (1, 2),
(1, 3), (1, 6), (2, 6), (4, 5)]), 2: set([(1, 2, 6)]), -1: set([()])}
So the face seems to have been added.
But then:
sage: T.homology()
results in:
{0: 0, 1: Z^10, 2: 0}
But this doesn't make any sense --- it should say `0:0, 1:Z^9, 2:0`, since adding a 2-face kills a class in $H_1(T)$.
Can anyone tell what I'm doing wrong?
MattKahleSun, 24 Mar 2013 17:40:49 +0100https://ask.sagemath.org/question/9943/Generate Maximal subsets based on mutual/subset propertyhttps://ask.sagemath.org/question/10316/generate-maximal-subsets-based-on-mutualsubset-property/Sorry for the imprecise language - I'm not a mathematician.
Given a list/set/dict/etc., is there a function/method available that will generate subsets, with the possibility of non-null intersections, based on some user defined mutual/subset property?
E.g., given a list [0,1,2,3,4,5], generate the maximal lists such that the maximum difference within each list is 3. For the given list, the function would produce [[0,1,2,3],[1,2,3,4],[2,3,4,5]]. For the list [0,3,9,10,17,30,33], this function would produce [[0,3],[9,10],[17],[30,33]].
This is different than the usual filtering operation in that the defining property is about the returned lists/sets/etc., not just about the individual elements.
Function should work with members of ZZ, QQ, RR, RDF, CC, CDF, and others if possible.rickhg12hsThu, 04 Jul 2013 04:54:17 +0200https://ask.sagemath.org/question/10316/error computing homology of a simplicial complexhttps://ask.sagemath.org/question/10117/error-computing-homology-of-a-simplicial-complex/I'm running code to first generate a simplicial complex that is just a 3 dimensional lattice. I'm then adding square plaquettes. However, I get an error sometimes when I try to calculate homology. Specifically, when I run the code below I get the error:
> ValueError: The differentials d_{2} and d_{1} are not compatible: their
composition is not zero.
This seems strange since a simplicial complex should always have homology. The error persists even when I specify the homology function to use different algorithms.
def grid(n1, n2=None, n3=None):
if n2 == None:
n2 = n1
if n3 == None:
n3 = n1
edges = []
for i in range(n1+1):
for j in range(n2+1):
for k in range(n3+1):
if i < n:
edges.append(((i,j,k),(i+1,j,k)))
if j < n:
edges.append(((i,j,k),(i,j+1,k)))
if k < n:
edges.append(((i,j,k),(i,j,k+1)))
return edges
def add_plaquette(complex, address):
b = address[1]
a1 = address[2]
a2 = address[3]
if address[0] == 2:
complex.add_face(((a1,a2,b),(a1+1,a2,b),(a1,a2+1,b)))
complex.add_face(((a1+1,a2+1,b),(a1+1,a2,b),(a1,a2+1,b)))
if address[0] == 1:
complex.add_face(((a1,b,a2),(a1+1,b,a2),(a1,b,a2+1)))
complex.add_face(((a1+1,b,a2+1),(a1+1,b,a2),(a1,b,a2+1)))
if address[0] == 0:
complex.add_face(((b,a1,a2),(b,a1+1,a2),(b,a1,a2+1)))
complex.add_face(((b,a1+1,a2+1),(b,a1+1,a2),(b,a1,a2+1)))
t0 = SimplicialComplex(grid(2))
add_plaquette(t0, (0,0,1,0))
add_plaquette(t0, (0,0,1,1))
add_plaquette(t0, (2,2,0,1))
t0.homology()
The full text of the error is:
> Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_8.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("I2dpdmVzIGVycm9yIHNhdmUhISEKdDAgPSBTaW1wbGljaWFsQ29tcGxleChncmlkKDIpKQphZGRfcGxhcXVldHRlKHQwLCAoMCwwLDEsMCkpCmFkZF9wbGFxdWV0dGUodDAsICgwLDAsMSwxKSkKYWRkX3BsYXF1ZXR0ZSh0MCwgKDIsMiwwLDEpKQp0MC5ob21vbG9neSgp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
> File "", line 1, in <module>
> File "/tmp/tmpBNPSQ1/___code___.py", line 7, in <module>
exec compile(u't0.homology()
> File "", line 1, in <module>
> File "/home/sage/sage-5.9/local/lib/python2.7/site-packages/sage/homology/cell_complex.py", line 549, in homology
return self._homology_(dim, **kwds)
> File "/home/sage/sage-5.9/local/lib/python2.7/site-packages/sage/homology/simplicial_complex.py", line 1925, in _homology_
cochain=cohomology, **kwds)
> File "/home/sage/sage-5.9/local/lib/python2.7/site-packages/sage/homology/simplicial_complex.py", line 1788, in chain_complex
return ChainComplex(data=differentials, degree=-1, **kwds)
> File "/home/sage/sage-5.9/local/lib/python2.7/site-packages/sage/homology/chain_complex.py", line 462, in __init__
raise ValueError, "The differentials d_{%s} and d_{%s} are not compatible: their composition is not zero." % (n, n+degree)
>ValueError: The differentials d_{2} and d_{1} are not compatible: their composition is not zero.parsons.kyle.89Mon, 13 May 2013 22:48:01 +0200https://ask.sagemath.org/question/10117/