Ask Your Question
2

error computing homology of a simplicial complex

asked 2013-05-13 22:48:01 +0100

parsons.kyle.89 gravatar image

updated 2023-01-10 00:01:08 +0100

tmonteil gravatar image

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.

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted
1

answered 2013-05-14 06:36:03 +0100

Volker Braun gravatar image

Confirmed, this is now Trac #14578

PS: Your grid() method refers to the undeclared n, this is a bug in your code. But not the reason for the ValueError.

edit flag offensive delete link more

Comments

There is now a patch up. With the patch in place, the code runs without error, and the homology of `t0` is `ZZ^25` in dimension 1, 0 otherwise.

John Palmieri gravatar imageJohn Palmieri ( 2013-05-14 15:15:06 +0100 )edit
1

answered 2013-05-14 12:23:04 +0100

I think the problem is the add_face method. If you define the same complex, specifying all of the facets at once, then it ought to work, so a workaround: once you've defined t0 as above:

sage: t0_fixed = SimplicialComplex(t0.facets())
edit flag offensive delete link more

Comments

`add_face` has been fixed in the patch at http://trac.sagemath.org/sage_trac/ticket/14578.

John Palmieri gravatar imageJohn Palmieri ( 2013-05-14 15:17:05 +0100 )edit
1

answered 2013-05-14 06:54:10 +0100

vdelecroix gravatar image

Hello,

The method which fails is delta_complex which is inderectly called with homology. As a quick workaround (I did not completely debug) it seems that simplical complexes do not like vertices other than 0, 1, 2, ...

In particular, the following version of your code does work

def t2i(i,j,k,n=2):
    return i+n*(j+n*k)

def grid(n=2):
    edges = []
    for i in range(n+1):
        for j in range(n+1):
            for k in range(n+1):
                if i < n:
                    edges.append([t2i(i,j,k,n),t2i(i+1,j,k,n)])
                if j < n:
                    edges.append([t2i(i,j,k,n),t2i(i,j+1,k,n)])
                if k < n:
                    edges.append([t2i(i,j,k,n),t2i(i,j,k+1,n)])
    return edges

def add_plaquette(complex, address, n=2):
    b = address[1]
    a1 = address[2]
    a2 = address[3]
    if address[0] == 2:
        F1 = ((a1,a2,b),(a1+1,a2,b),(a1,a2+1,b))
        F2 = ((a1+1,a2+1,b),(a1+1,a2,b),(a1,a2+1,b))
    if address[0] == 1:
        F1 = ((a1,b,a2),(a1+1,b,a2),(a1,b,a2+1))
        F2 = ((a1+1,b,a2+1),(a1+1,b,a2),(a1,b,a2+1))
    if address[0] == 0:
        F1 = ((b,a1,a2),(b,a1+1,a2),(b,a1,a2+1))
        F2 = ((b,a1+1,a2+1),(b,a1+1,a2),(b,a1,a2+1))
    complex.add_face([t2i(i,j,k,n) for i,j,k in F1])
    complex.add_face([t2i(i,j,k,n) for i,j,k in F2])

I then get the answer

 {0: 0, 1: Z^18, 2: 0}
edit flag offensive delete link more

Comments

It has something to do with the ordering for sure, but its not as easy as you make it. The testcase in #14578 fails with integer vertex labels, too.

Volker Braun gravatar imageVolker Braun ( 2013-05-14 08:15:18 +0100 )edit

Then, it is a real mystery ! (I do not want to bet on the trueness of Sage's answer in my code)

vdelecroix gravatar imagevdelecroix ( 2013-05-14 15:01:25 +0100 )edit

I don't think that `delta_complex` is involved here.

John Palmieri gravatar imageJohn Palmieri ( 2013-05-14 15:22:59 +0100 )edit

Perhaps not, but calling t0.delta_complex() fails (and I guess that it is inside that function that the condition on the derivation is tested).

vdelecroix gravatar imagevdelecroix ( 2013-05-14 16:41:38 +0100 )edit

I think that `t0.delta_complex()` fails because of the inconsistent ordering of the vertices in the facets. When defining a Delta complex, you need to be very careful about such orderings, so it is not that surprising that this fails. Sorting the facets as they are added seems to fix both problems.

John Palmieri gravatar imageJohn Palmieri ( 2013-05-14 16:53:36 +0100 )edit
0

answered 2013-06-27 15:21:01 +0100

tmonteil gravatar image

This bug is fixed in sage 5.10 (trac ticket 14578), and you will now get the following answer :

{0: 0, 1: Z^25, 2: 0}

But a previous answer of @vdelecroix suggests that the answer could be:

{0: 0, 1: Z^18, 2: 0}

Perhaps there is a problem somewhere, what should be the right result ?

edit flag offensive delete link more

Comments

The cell count is sage: [len(t0.cells()[i]) for i in range(3)] [54, 84, 6] so the Euler characteristic is -24. Only the former answer can be correct. Note that it is reduced homology, hence the offset by one.

Volker Braun gravatar imageVolker Braun ( 2013-06-27 17:15:43 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-05-13 22:48:01 +0100

Seen: 631 times

Last updated: Jun 27 '13