ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 28 Oct 2018 03:55:39 -0500ChainComplex() runs 24 times slower than homology()http://ask.sagemath.org/question/44101/chaincomplex-runs-24-times-slower-than-homology/I load a list of matrices `bdrs` representing a chain complex, their dimensions are
{1, 21, 210, 1330, 5985, 20349, 54264, 116280, 203490, 293930, 352716, 352716, 293930, 203490, 116280, 54264, 20349, 5985, 1330, 210, 21, 1}, and the largest has density 3.91*10^-6. In total they take up 50MB of disk space. This finishes in 63sec.
When I run `chcx=ChainComplex(bdrs,base_ring=GF(2))`, it takes 7hrs20min, but `chcx.homology()` finishes in only 18min. **Why does it take so long to just store a few matrices?** At first I thought that `ChainComplex()` also does some simplifications/reductions, but `[chcx.free_module_rank(i) for i in range(0,21)]` shows the original dimensions of matrices :/.
**Is there a faster way to compute the homology** of a chain complex (over $\mathbb{Z}$ or $\mathbb{Z}_p$)?LeonSun, 28 Oct 2018 03:55:39 -0500http://ask.sagemath.org/question/44101/Obtaining symbolic generators from homology()http://ask.sagemath.org/question/29601/obtaining-symbolic-generators-from-homology/I need to compute the homology of a chain complex whose graded basis is a collection of formal symbols, say {a,b,c,…}.
Does Sage have the capability to store a basis of symbols and express a homology class in terms of a symbolic class representative?
I have been able to able to create a ChainComplex instance using matrices for the boundary maps. For example,
TorusComplex = ChainComplex({0: matrix(Z_2,2,1,[0,0],sparse=True),1: matrix(Z_2,1,2,[0,0],sparse=True)})
"Chain complex with at most 3 nonzero terms over Ring of integers modulo 2"
TorusComplex.homology(generators=true)
"{0: (Vector space of dimension 1 over Ring of integers modulo 2, [(1)]), 1: (Vector space of dimension 2 over Ring of integers modulo 2, [(1, 0), (0, 1)]), 2: (Vector space of dimension 1 over Ring of integers modulo 2, [(1)])}"
However, I can't figure out how define symbols so that the resulting generators are symbols. Any ideas?mfanslerSat, 26 Sep 2015 15:21:07 -0500http://ask.sagemath.org/question/29601/sparse differential of a chain complexhttp://ask.sagemath.org/question/10415/sparse-differential-of-a-chain-complex/I'm trying to convert a simplicial complex into a chain complex and then extract the differential map. However the simplicial complex is rather large and sage runs out of memory when it tries to make the conversion. However, the differential should be a very sparse matrix and there should be plenty of memory to store a sparse representation of the differential. Is it possible to have sage compute the differential as a sparse matrix? Specifically the method which gives the out of memory error is `chain_complex()`.parsons.kyle.89Mon, 05 Aug 2013 11:16:29 -0500http://ask.sagemath.org/question/10415/problem extracting the differentials of a chain complexhttp://ask.sagemath.org/question/10192/problem-extracting-the-differentials-of-a-chain-complex/I'm getting an error when trying to convert a simplicial complex into a chain complex and then extract the differential maps using the .differential operator.
def grid1d(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 < n1:
edges.append(((i,j,k),(i+1,j,k)))
if j < n2:
edges.append(((i,j,k),(i,j+1,k)))
if k < n3:
edges.append(((i,j,k),(i,j,k+1)))
return edges
comp = SimplicialComplex(grid1d(3))
chain = comp.chain_complex()
chain.differential()
Everything runs but the last line which gives me the error:
> {0: Traceback (most recent call last):
File "stdin", line 1, in module
File "_sage_input_52.py", line 10, in module
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("Y29tcCA9IFNpbXBsaWNpYWxDb21wbGV4KGdyaWQxZCgzKSkKY2hhaW4gPSBjb21wLmNoYWluX2NvbXBsZXgoKQpjaGFpbi5kaWZmZXJlbnRpYWwoKQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in module
> File "/tmp/tmpZ7wtbe/___code___.py", line 5, in module
exec compile(u'chain.differential()
File "", line 1, in module
> File "matrix0.pyx", line 1729, in sage.matrix.matrix0.Matrix.__repr__ (sage/matrix/matrix0.c:9374)
File "/home/sage/sage-5.9/local/lib/python2.7/site-packages/sage/misc/sageinspect.py", line 1915, in sage_getvariablename
for frame in inspect.stack():
File "/home/sage/sage-5.9/local/lib/python/inspect.py", line 1054, in stack
return getouterframes(sys._getframe(1), context)
File "/home/sage/sage-5.9/local/lib/python/inspect.py", line 1032, in getouterframes
framelist.append((frame,) + getframeinfo(frame, context))
File "/home/sage/sage-5.9/local/lib/python/inspect.py", line 1007, in getframeinfo
lines, lnum = findsource(frame)
File "/home/sage/sage-5.9/local/lib/python/inspect.py", line 528, in findsource
if not sourcefile and file[0] + file[-1] != '<>':
IndexError: string index out of range
Any help resolving this problem would be greatly appreciated.parsons.kyle.89Tue, 04 Jun 2013 11:25:08 -0500http://ask.sagemath.org/question/10192/Homology of chain complexeshttp://ask.sagemath.org/question/9159/homology-of-chain-complexes/I've got the following chain complex:
0->ZZ^2->ZZ^4->ZZ^3->0
With the boundarymaps given by
d0:(z1,z2,z3) |-> 0
d1:(z1,z2,z3,z4) |-> (-2(z1+z3+z4), 2(z1-z2), z2+z3+z4)
d2:(z1,z2)|-> (z1+z2, z1+z2,-z1,-z2)
Now I tried to compute the homology groups (e.g. H0 = ker d0 / im d1) using sage. One time manually via taking the quotients of the respective modules, one time using the ChainComplex() module. However, I don't really understand the output using the first method (e.g. what means: "Finitely generated module V/W over Integer Ring with invariants (2, 0)"), and both methods seem to deliver different results...
I've defined my boundary maps as matrices:
d0 = matrix(ZZ, 1,3,[[0,0,0]]).transpose()
d1 = matrix(ZZ, 3,4,[[-2,0,-2,-2],[2,-2,0,0],[0,1,1,1]]).transpose()
d2 = matrix(ZZ,4,2,[[1,1],[1,1],[-1,0],[0,-1]]).transpose()
Where I've taken the transpose since I'm used to write linear maps as d(x) = D*x, whereas sage seems to use d(x) = x*D, where D is the corresponding matrix.
Calculating the homology groups via
H0 = d0.kernel()/d1.image()
H1 = d1.kernel()/d2.image()
H2 = d2.kernel()
gives the following results:
H0: Finitely generated module V/W over Integer Ring with invariants (2, 0)
H1: Finitely generated module V/W over Integer Ring with invariants ()
H2: Free module of degree 2 and rank 0 over Integer Ring
whereas
ChainComplex([d0,d1,d2]).homology()
yields a different strucure.
{0: Z, 1: Z, 2: C2, 3: 0}
To maximize confusion, calculation by hand gives me H0=C2^2 x ZZ, H1=0, H2=0. I'd might have made some mistakes there, though. So I don't really konw how to interpret the results from Sage.romanWed, 18 Jul 2012 02:30:25 -0500http://ask.sagemath.org/question/9159/