####################################################################
#To run this program without retyping                              #
#download this text file as e.g. MAPPRO into bin, then             #
#in Maple type: `read MAPPRO': [without the quotes] to run.        #
####################################################################
 
#MAPPRO is a Maple routine written by F.W. Roush, slightly
#modified by M. Boyle, to accompany the paper
#"The Williams conjecture is false for irreducible subshifts"
#by K. H. Kim and F. W. Roush. (ERA-AMS, v.3)
#This routine computes sgc_2 described in the paper.

with(linalg):
 
sgcc:=proc(r,s,m,n) sgcc2:=0;
 
for i from 1 to m do: 

for j from i+1 to m do: 

for k from 1 to n do: 

for l from 1 to k-1 do:

sgcc2:=sgcc2 + r[i,k]*s[k,i]*r[j,l]*s[l,j]:

od: od: od: od: 
 

for i from 1 to m do: 

for j from i+1 to m do: 

for k from 1 to n do: 

for l from 1 to k do: 

sgcc2:=sgcc2 + r[i,k]*s[k,j]*r[j,l]*s[l,i]:

od:od:od:od:
 

for i from 1 to m do: 

for k from 1 to n do: 

sgcc2:=sgcc2 +  (r[i,k]*(r[i,k]-1)*(s[k,i])\^2)/2:

od:od:

 return(sgcc2);end;

print(`This gives sgc2 where r is m x n;example; sgcc r,s=1, sgcc s,r=0`);

with(linalg);r:=matrix(2,2,[1,0,0,1]);s:=matrix(2,2,[1,1,1,1]);
sgcc(r,s,2,2);sgcc(s,r,2,2);