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, 27 Jun 2013 17:15:43 +0200error 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.Mon, 13 May 2013 22:48:01 +0200https://ask.sagemath.org/question/10117/error-computing-homology-of-a-simplicial-complex/Answer by John Palmieri for <p>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:</p>
<blockquote>
<p>ValueError: The differentials d_{2} and d_{1} are not compatible: their
composition is not zero.</p>
</blockquote>
<p>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.</p>
<pre><code>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()
</code></pre>
<p>The full text of the error is:</p>
<blockquote>
<p>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("# -<em>- coding: utf-8 -</em>-\n" + _support_.preparse_worksheet_cell(base64.b64decode("I2dpdmVzIGVycm9yIHNhdmUhISEKdDAgPSBTaW1wbGljaWFsQ29tcGxleChncmlkKDIpKQphZGRfcGxhcXVldHRlKHQwLCAoMCwwLDEsMCkpCmFkZF9wbGFxdWV0dGUodDAsICgwLDAsMSwxKSkKYWRkX3BsYXF1ZXR0ZSh0MCwgKDIsMiwwLDEpKQp0MC5ob21vbG9neSgp"),globals())+"\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module></p>
<p>File "/tmp/tmpBNPSQ1/___code___.py", line 7, in <module>
exec compile(u't0.homology()
File "", line 1, in <module></p>
<p>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, <em>*kwds)
File "/home/sage/sage-5.9/local/lib/python2.7/site-packages/sage/homology/simplicial_complex.py", line 1925, in _homology_
cochain=cohomology, *</em>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.</p>
</blockquote>
https://ask.sagemath.org/question/10117/error-computing-homology-of-a-simplicial-complex/?answer=14922#post-id-14922I 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())
Tue, 14 May 2013 12:23:04 +0200https://ask.sagemath.org/question/10117/error-computing-homology-of-a-simplicial-complex/?answer=14922#post-id-14922Comment by John Palmieri for <p>I think the problem is the <code>add_face</code> 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 <code>t0</code> as above:</p>
<pre><code>sage: t0_fixed = SimplicialComplex(t0.facets())
</code></pre>
https://ask.sagemath.org/question/10117/error-computing-homology-of-a-simplicial-complex/?comment=17699#post-id-17699`add_face` has been fixed in the patch at http://trac.sagemath.org/sage_trac/ticket/14578.Tue, 14 May 2013 15:17:05 +0200https://ask.sagemath.org/question/10117/error-computing-homology-of-a-simplicial-complex/?comment=17699#post-id-17699Answer by vdelecroix for <p>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:</p>
<blockquote>
<p>ValueError: The differentials d_{2} and d_{1} are not compatible: their
composition is not zero.</p>
</blockquote>
<p>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.</p>
<pre><code>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()
</code></pre>
<p>The full text of the error is:</p>
<blockquote>
<p>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("# -<em>- coding: utf-8 -</em>-\n" + _support_.preparse_worksheet_cell(base64.b64decode("I2dpdmVzIGVycm9yIHNhdmUhISEKdDAgPSBTaW1wbGljaWFsQ29tcGxleChncmlkKDIpKQphZGRfcGxhcXVldHRlKHQwLCAoMCwwLDEsMCkpCmFkZF9wbGFxdWV0dGUodDAsICgwLDAsMSwxKSkKYWRkX3BsYXF1ZXR0ZSh0MCwgKDIsMiwwLDEpKQp0MC5ob21vbG9neSgp"),globals())+"\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module></p>
<p>File "/tmp/tmpBNPSQ1/___code___.py", line 7, in <module>
exec compile(u't0.homology()
File "", line 1, in <module></p>
<p>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, <em>*kwds)
File "/home/sage/sage-5.9/local/lib/python2.7/site-packages/sage/homology/simplicial_complex.py", line 1925, in _homology_
cochain=cohomology, *</em>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.</p>
</blockquote>
https://ask.sagemath.org/question/10117/error-computing-homology-of-a-simplicial-complex/?answer=14920#post-id-14920Hello,
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}Tue, 14 May 2013 06:54:10 +0200https://ask.sagemath.org/question/10117/error-computing-homology-of-a-simplicial-complex/?answer=14920#post-id-14920Comment by vdelecroix for <p>Hello,</p>
<p>The method which fails is <strong>delta_complex</strong> which is inderectly called with <strong>homology</strong>. As a quick workaround (I did not completely debug) it seems that simplical complexes do not like vertices other than 0, 1, 2, ...</p>
<p>In particular, the following version of your code does work</p>
<pre><code>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])
</code></pre>
<p>I then get the answer</p>
<pre><code> {0: 0, 1: Z^18, 2: 0}
</code></pre>
https://ask.sagemath.org/question/10117/error-computing-homology-of-a-simplicial-complex/?comment=17695#post-id-17695I see. Thanks for your clarification !Tue, 14 May 2013 16:57:21 +0200https://ask.sagemath.org/question/10117/error-computing-homology-of-a-simplicial-complex/?comment=17695#post-id-17695Comment by John Palmieri for <p>Hello,</p>
<p>The method which fails is <strong>delta_complex</strong> which is inderectly called with <strong>homology</strong>. As a quick workaround (I did not completely debug) it seems that simplical complexes do not like vertices other than 0, 1, 2, ...</p>
<p>In particular, the following version of your code does work</p>
<pre><code>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])
</code></pre>
<p>I then get the answer</p>
<pre><code> {0: 0, 1: Z^18, 2: 0}
</code></pre>
https://ask.sagemath.org/question/10117/error-computing-homology-of-a-simplicial-complex/?comment=17696#post-id-17696I 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.Tue, 14 May 2013 16:53:36 +0200https://ask.sagemath.org/question/10117/error-computing-homology-of-a-simplicial-complex/?comment=17696#post-id-17696Comment by John Palmieri for <p>Hello,</p>
<p>The method which fails is <strong>delta_complex</strong> which is inderectly called with <strong>homology</strong>. As a quick workaround (I did not completely debug) it seems that simplical complexes do not like vertices other than 0, 1, 2, ...</p>
<p>In particular, the following version of your code does work</p>
<pre><code>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])
</code></pre>
<p>I then get the answer</p>
<pre><code> {0: 0, 1: Z^18, 2: 0}
</code></pre>
https://ask.sagemath.org/question/10117/error-computing-homology-of-a-simplicial-complex/?comment=17698#post-id-17698I don't think that `delta_complex` is involved here.Tue, 14 May 2013 15:22:59 +0200https://ask.sagemath.org/question/10117/error-computing-homology-of-a-simplicial-complex/?comment=17698#post-id-17698Comment by Volker Braun for <p>Hello,</p>
<p>The method which fails is <strong>delta_complex</strong> which is inderectly called with <strong>homology</strong>. As a quick workaround (I did not completely debug) it seems that simplical complexes do not like vertices other than 0, 1, 2, ...</p>
<p>In particular, the following version of your code does work</p>
<pre><code>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])
</code></pre>
<p>I then get the answer</p>
<pre><code> {0: 0, 1: Z^18, 2: 0}
</code></pre>
https://ask.sagemath.org/question/10117/error-computing-homology-of-a-simplicial-complex/?comment=17705#post-id-17705It 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.Tue, 14 May 2013 08:15:18 +0200https://ask.sagemath.org/question/10117/error-computing-homology-of-a-simplicial-complex/?comment=17705#post-id-17705Comment by vdelecroix for <p>Hello,</p>
<p>The method which fails is <strong>delta_complex</strong> which is inderectly called with <strong>homology</strong>. As a quick workaround (I did not completely debug) it seems that simplical complexes do not like vertices other than 0, 1, 2, ...</p>
<p>In particular, the following version of your code does work</p>
<pre><code>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])
</code></pre>
<p>I then get the answer</p>
<pre><code> {0: 0, 1: Z^18, 2: 0}
</code></pre>
https://ask.sagemath.org/question/10117/error-computing-homology-of-a-simplicial-complex/?comment=17697#post-id-17697Perhaps not, but calling t0.delta_complex() fails (and I guess that it is inside that function that the condition on the derivation is tested).Tue, 14 May 2013 16:41:38 +0200https://ask.sagemath.org/question/10117/error-computing-homology-of-a-simplicial-complex/?comment=17697#post-id-17697Comment by vdelecroix for <p>Hello,</p>
<p>The method which fails is <strong>delta_complex</strong> which is inderectly called with <strong>homology</strong>. As a quick workaround (I did not completely debug) it seems that simplical complexes do not like vertices other than 0, 1, 2, ...</p>
<p>In particular, the following version of your code does work</p>
<pre><code>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])
</code></pre>
<p>I then get the answer</p>
<pre><code> {0: 0, 1: Z^18, 2: 0}
</code></pre>
https://ask.sagemath.org/question/10117/error-computing-homology-of-a-simplicial-complex/?comment=17702#post-id-17702Then, it is a real mystery ! (I do not want to bet on the trueness of Sage's answer in my code)Tue, 14 May 2013 15:01:25 +0200https://ask.sagemath.org/question/10117/error-computing-homology-of-a-simplicial-complex/?comment=17702#post-id-17702Answer by tmonteil for <p>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:</p>
<blockquote>
<p>ValueError: The differentials d_{2} and d_{1} are not compatible: their
composition is not zero.</p>
</blockquote>
<p>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.</p>
<pre><code>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()
</code></pre>
<p>The full text of the error is:</p>
<blockquote>
<p>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("# -<em>- coding: utf-8 -</em>-\n" + _support_.preparse_worksheet_cell(base64.b64decode("I2dpdmVzIGVycm9yIHNhdmUhISEKdDAgPSBTaW1wbGljaWFsQ29tcGxleChncmlkKDIpKQphZGRfcGxhcXVldHRlKHQwLCAoMCwwLDEsMCkpCmFkZF9wbGFxdWV0dGUodDAsICgwLDAsMSwxKSkKYWRkX3BsYXF1ZXR0ZSh0MCwgKDIsMiwwLDEpKQp0MC5ob21vbG9neSgp"),globals())+"\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module></p>
<p>File "/tmp/tmpBNPSQ1/___code___.py", line 7, in <module>
exec compile(u't0.homology()
File "", line 1, in <module></p>
<p>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, <em>*kwds)
File "/home/sage/sage-5.9/local/lib/python2.7/site-packages/sage/homology/simplicial_complex.py", line 1925, in _homology_
cochain=cohomology, *</em>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.</p>
</blockquote>
https://ask.sagemath.org/question/10117/error-computing-homology-of-a-simplicial-complex/?answer=15152#post-id-15152This bug is fixed in sage 5.10 ([trac ticket 14578](http://trac.sagemath.org/sage_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 ?
Thu, 27 Jun 2013 15:21:01 +0200https://ask.sagemath.org/question/10117/error-computing-homology-of-a-simplicial-complex/?answer=15152#post-id-15152Comment by Volker Braun for <p>This bug is fixed in sage 5.10 (<a href="http://trac.sagemath.org/sage_trac/ticket/14578">trac ticket 14578</a>), and you will now get the following answer :</p>
<pre><code>{0: 0, 1: Z^25, 2: 0}
</code></pre>
<p>But a previous answer of <a href="/users/87/vdelecroix/">@vdelecroix</a> suggests that the answer could be:</p>
<pre><code>{0: 0, 1: Z^18, 2: 0}
</code></pre>
<p>Perhaps there is a problem somewhere, what should be the right result ?</p>
https://ask.sagemath.org/question/10117/error-computing-homology-of-a-simplicial-complex/?comment=17440#post-id-17440The 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.Thu, 27 Jun 2013 17:15:43 +0200https://ask.sagemath.org/question/10117/error-computing-homology-of-a-simplicial-complex/?comment=17440#post-id-17440Answer by Volker Braun for <p>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:</p>
<blockquote>
<p>ValueError: The differentials d_{2} and d_{1} are not compatible: their
composition is not zero.</p>
</blockquote>
<p>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.</p>
<pre><code>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()
</code></pre>
<p>The full text of the error is:</p>
<blockquote>
<p>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("# -<em>- coding: utf-8 -</em>-\n" + _support_.preparse_worksheet_cell(base64.b64decode("I2dpdmVzIGVycm9yIHNhdmUhISEKdDAgPSBTaW1wbGljaWFsQ29tcGxleChncmlkKDIpKQphZGRfcGxhcXVldHRlKHQwLCAoMCwwLDEsMCkpCmFkZF9wbGFxdWV0dGUodDAsICgwLDAsMSwxKSkKYWRkX3BsYXF1ZXR0ZSh0MCwgKDIsMiwwLDEpKQp0MC5ob21vbG9neSgp"),globals())+"\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module></p>
<p>File "/tmp/tmpBNPSQ1/___code___.py", line 7, in <module>
exec compile(u't0.homology()
File "", line 1, in <module></p>
<p>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, <em>*kwds)
File "/home/sage/sage-5.9/local/lib/python2.7/site-packages/sage/homology/simplicial_complex.py", line 1925, in _homology_
cochain=cohomology, *</em>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.</p>
</blockquote>
https://ask.sagemath.org/question/10117/error-computing-homology-of-a-simplicial-complex/?answer=12379#post-id-12379Confirmed, this is now [Trac #14578](http://trac.sagemath.org/sage_trac/ticket/14578)
PS: Your grid() method refers to the undeclared n, this is a bug in your code. But not the reason for the ValueError.Tue, 14 May 2013 06:36:03 +0200https://ask.sagemath.org/question/10117/error-computing-homology-of-a-simplicial-complex/?answer=12379#post-id-12379Comment by John Palmieri for <p>Confirmed, this is now <a href="http://trac.sagemath.org/sage_trac/ticket/14578">Trac #14578</a></p>
<p>PS: Your grid() method refers to the undeclared n, this is a bug in your code. But not the reason for the ValueError.</p>
https://ask.sagemath.org/question/10117/error-computing-homology-of-a-simplicial-complex/?comment=17700#post-id-17700There 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.Tue, 14 May 2013 15:15:06 +0200https://ask.sagemath.org/question/10117/error-computing-homology-of-a-simplicial-complex/?comment=17700#post-id-17700