# Bug with simplicial complexes or computing homology in Sage 7.3?

I have the following code that has been running fine in Sage 6.5––Sage 7.2 on both my Mac OS 10.10.5 and a Unix system. I just tried upgrading to Sage 7.3 on my Mac, and it no longer works correctly. It doesn't crash, it just gives wrong answers.

I will copy the code below, but it reminds me of the issue I had when I posted the following question: https://ask.sagemath.org/question/994...

The code below is complicated, but the output of sampler(n) is supposed to be a random Q-acyclic simplicial complex with n vertices. So if I write

S=sampler(12)
S.homology()


I should expect to see something like

{0: 0, 1: 0, 1: 0} or {0: 0, 1: C2, 1: 0} as outputs,

but definitely not {0: 0, 1: Z, 2: Z}

The homology should be trivial or finite groups. But in Sage 7.3 on my Mac, I get Z parts in the homology. I thought my code was broken at first, but copying and pasting it back into Sage 7.2 on my Mac, it seems to work fine.

@cached_function
def f(X):
return (X.transpose() * X).inverse()

def ortho(X):
X.set_immutable()
return X*f(X)* X.transpose()

def TR(M):
D=M.diagonal()
X=GeneralDiscreteDistribution(D)
return X.get_random_element()

def shrink(X,Q,n):
W=Q[:,n]
W.set_immutable()
X2=X-W*f(W)*W.transpose()*X
X3=X2.transpose().echelon_form().transpose()
return X3[:,0:X3.ncols()-1]

def sampler(N):
S=range(1,N+1)
Z = SimplicialComplex(Set(range(1, N+1)).subsets(3))
L=list(Z.n_faces(2))
T=Z.n_skeleton(1)
C=Z.chain_complex()
M=C.differential(2).dense_matrix().transpose()
M2=M.transpose().echelon_form().transpose()
R=M2.rank()
X=M2[:,0:R]
Q=ortho(X)
n=TR(Q)
j = binomial(N,2) - N
for i in range(j):
X=shrink(X,Q,n)
Q=ortho(X)
n=TR(Q)
return(T)

edit retag close merge delete

Sort by » oldest newest most voted

I think the issue is that between versions 7.2 and 7.3, Sage changed the way n_faces is implemented. If you care about the ordering of the results, use n_cells instead. That's what you should do here, because n_cells uses an ordering consistent with that of the matrices defining the chain complex. I think the fact that it worked before was a lucky accident -- the ordering in the output from n_faces was essentially random in 7.2 (since n_faces returns a set), but your code happened to work: I think the old Sage code used the same essentially random ordering when constructing the chain complex, whereas the new code is more careful to order things in a well-defined way and to always use that ordering.

more