Ask Your Question
2

Bug with simplicial complexes or computing homology in Sage 7.3?

asked 2016-10-03 21:44:35 -0500

updated 2016-10-03 22:47:03 -0500

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)
    T.add_face(list(L[n]))
    j = binomial(N,2) - N
    for i in range(j):
        X=shrink(X,Q,n)
        Q=ortho(X)
        n=TR(Q)
        T.add_face(list(L[n]))
    return(T)
edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
3

answered 2016-10-04 13:08:28 -0500

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.

edit flag offensive delete link more

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: 2016-10-03 21:44:35 -0500

Seen: 60 times

Last updated: Oct 04 '16