Skip to content

Instantly share code, notes, and snippets.

@amitjamadagni
Created March 7, 2014 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amitjamadagni/9420632 to your computer and use it in GitHub Desktop.
Save amitjamadagni/9420632 to your computer and use it in GitHub Desktop.
A very initial implementation of Seifert Matrix.
from sage.matrix.constructor import identity_matrix, matrix
def components(x):
new = []
for i in range(len(x)):
a = abs(x[i])
new.append(a)
print new
sorted = list(set(new))
print sorted
'''sorting the absolute values of the braid word'''
difference = []
difference.append(sorted[0] - 1)
for i in range(1,len(sorted)):
difference.append(sorted[i]-sorted[i-1])
print difference
q=0
missing = []
for i in range(len(difference)):
a = difference[i]-1
for k in range(1,a+1):
q = q + 1
missing.append(sorted[i-1] + k)
print missing
h = []
for j in range(len(new)):
a = new[j]
for i in range(j+1,len(new)):
if(a == new[i]):
h.append(i)
break
else:
h.append(0)
print h
hlen=len(h)
m = matrix(hlen)
a = []
a = m.columns()
b = []
for i in range(len(a)):
b.append(list(a[i]))
for i in range(len(x)-1):
if((x[i]>0 and x[h[i]]<0) or (x[i]<0 and x[h[i]]>0)):
b[i][i]=0
if(x[i]>0 and x[h[i]]>0):
b[i][i]=-1
if(x[i]<0 and x[h[i]]<0):
b[i][i]=1
for i in range(hlen):
if(h[i]!=0):
for j in range(hlen):
if(i<j and h[i]>h[j]):
b[i][j]=0
b[j][i]=0
if(i<j and h[i] < j):
b[i][j]=0
b[j][i]=0
if(i<j and h[i]==j):
if(x[j]>0):
b[i][j]=0
b[j][i]=1
else:
b[i][j]=-1
b[j][i]=0
else:
if(abs(abs(x[i])-abs(x[j]))>1):
b[i][j]=0
if(abs(abs(x[i])-abs(x[j]))==1):
b[i][j]=0
b[i][j]=-1
if(abs(abs(x[j])-abs(x[i]))==1):
b[i][j]=1
b[j][i]=0
print b
x = [2,-2,-4,-2,3]
y = components(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment