Skip to content

Instantly share code, notes, and snippets.

@amitjamadagni
Created June 21, 2014 21:17
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/e3b956b36f6c52d4b3af to your computer and use it in GitHub Desktop.
Save amitjamadagni/e3b956b36f6c52d4b3af to your computer and use it in GitHub Desktop.
Seifert circles and the regions of the knot
def seifert_circles(self, oriented_gauss_code):
self.oriented_gauss_code = oriented_gauss_code
x = self.PD_code_ogc(self.oriented_gauss_code)
s = [[None for i in range(4)] for i in range(len(x))]
for i in range(len(x)):
s[i][0] = 'entering'
s[i][2] = 'leaving'
if self.oriented_gauss_code[1][i] == '-':
s[i][1] = 'leaving'
s[i][3] = 'entering'
elif self.oriented_gauss_code[1][i] == '+':
s[i][1] = 'entering'
s[i][3] = 'leaving'
x1 = x #the arrays are being copied, just a tag
s1 = s
r = [[[None,None],[None,None]] for i in range(len(x))]
for i in range(len(x)):
for j in [1,3]:
if s[i][j] == 'leaving':
r[i][0][0] = x1[i][0]
r[i][0][1] = x1[i][j]
del x1[i][j]
del x1[i][0]
del s1[i][j]
del s1[i][0]
break
for i in range(len(x)):
for j in [0,1]:
if s1[i][0] == "entering":
r[i][1][0] = x1[i][0]
r[i][1][1] = x1[i][1]
elif s1[i][0] == "leaving":
r[i][1][0] = x1[i][1]
r[i][1][1] = x1[i][0]
print r
r1 = [a for b in r for a in b]
dic = dict(sorted(r1))
for i in dic:
dic[i] = [dic[i]]
D = DiGraph(dic)
return D.all_simple_cycles()
def regions(self, oriented_gauss_code):
self.oriented_gauss_code = oriented_gauss_code
x = self.PD_code_ogc(self.oriented_gauss_code)
s = [[None for i in range(4)] for i in range(len(x))]
for i in range(len(x)):
s[i][0] = 'entering'
s[i][2] = 'leaving'
if self.oriented_gauss_code[1][i] == '-':
s[i][1] = 'leaving'
s[i][3] = 'entering'
elif self.oriented_gauss_code[1][i] == '+':
s[i][1] = 'entering'
s[i][3] = 'leaving'
ou = [["under","over","under","over"] for i in range(len(x))]
r = [[[None,None],[None,None]] for i in range(len(x))]
r1 = [[[None,None],[None,None]] for i in range(len(x))]
for i in range(len(x)):
r[i][0][0] = x[i][0]
r1[i][0][0] = "under"
for j in range(1,4):
if s[i][j] == "entering":
r[i][0][1] = x[i][j]
r1[i][0][1] = ou[i][j]
del x[i][j]
del ou[i][j]
s[i][j] = 0
del ou[i][0]
s[i][0] = 0
del x[i][0]
for i in range(len(x)):
r[i][1][0] = x[i][0]
r[i][1][1] = x[i][1]
r1[i][1][0] = ou[i][0]
r1[i][1][1] = ou[i][1]
del x[i][1]
del x[i][0]
del ou[i][1]
del ou[i][0]
gc_sign = self.oriented_gauss_code[1]
r = [a for b in r for a in b]
r1 = [a for b in r1 for a in b]
r3 = deepcopy(r)
lc = [[None,None] for i in range(len(x))]
for i in range(len(x)):
if gc_sign[i] == '-':
if r1[2*i+1][0] == 'over':
lc[i][0] = r[2*i+1][0]
lc[i][1] = (-1)*r[2*i][0]
elif gc_sign[i] == '+':
if r1[2*i+1][0] == 'under':
lc[i][1] = r[2*i+1][0]
lc[i][0] = (-1)*r[2*i][1]
r2 = []
for i in reversed(range(len(x))):
r2.append(r[2*i])
del r[2*i]
entering = r2[::-1]
left_component_entering = lc
leaving = r
r4 = deepcopy(r)
for i in r4:
i[0] = (-1)*i[0]
i[1] = (-1)*i[1]
lc1 = [[None,None] for i in range(len(x))]
for i in range(len(x)):
if gc_sign[i] == '-':
if r1[2*i+1][0] == 'over':
lc1[i][0] = r3[2*i+1][1]
if r1[2*i][0] == 'over':
lc1[i][1] = (-1)*r3[2*i][0]
elif r1[2*i][1] == 'over':
lc1[i][1] = (-1)*r3[2*i][1]
elif gc_sign[i] == '+':
if r1[2*i+1][1] == 'over':
lc1[i][0] = r3[2*i+1][1]
if r1[2*i][0] == 'under':
lc1[i][1] = (-1)*r3[2*i][0]
elif r1[2*i][1] == 'under':
lc1[i][1] = (-1)*r3[2*i][1]
left_component_leaving = lc1
'''
sage: L.regions([[-1, +2, -3, 1, -2, +3 ],['-','-','-']])
[[1, 4], [5, 2], [3, 6]]
[[5, -1], [3, -5], [1, -3]]
[[5, 2], [3, 6], [1, 4]]
read as 1 has left component as 5, 4 has left componet as -1, .....
read as [1,4], [5,2], [3,6] enter the crossing
read as [5,2], [3,6], [1,4] leave the crossing
this is with respect to the example we had in the email thread.
'''
w = {}
w1 = {}
for i in range(len(x)):
w.update({entering[i][0] : left_component_entering[i][0]})
w.update({entering[i][1] : left_component_entering[i][1]})
w1.update({r4[i][0] : left_component_leaving[i][0]})
w1.update({r4[i][1] : left_component_leaving[i][1]})
for i in range(1,len(w)+1):
w[i] = [w[i]]
for i in range(-len(w),0):
w1[i] = [w1[i]]
w2 = dict(w.items() + w1.items())
d = DiGraph(w2)
regions = d.all_simple_cycles()
for i in regions:
del i[0]
check = [i for i in range(-len(w), len(w)+1)]
del check[len(w)]
regions1 = [a for b in regions for a in b]
r5 = sorted(regions1)
if r5 == check:
return regions
else:
raise Exception("Incorrect Input")
'''
Example 1:
sage: from sage.knots import link
sage: L.seifert_circles([[-1, 2, 3, -4, 5, -6, 7, 8, -2, -5, +6, 1, -8, -3, -4, -7],['-','-','-','-','+','+','-','+']])
[[2, 10, 6, 12, 2], [4, 16, 8, 14, 4], [1, 13, 9, 3, 15, 5, 11, 7, 1]] \\ here the components should not repeat I have to add that.
sage: L.regions([[-1, 2, 3, -4, 5, -6, 7, 8, -2, -5, +6, 1, -8, -3, -4, -7],['-','-','-','-','+','+','-','+']])
[[6, -11],
[15, -4],
[9, 3, -14],
[2, -9, -13],
[1, 13, -8],
[12, -1, -7],
[5, 11, 7, -16],
[-3, 10, -5, -15],
[-6, -10, -2, -12],
[16, 8, 14, 4]]
Diagram of the knot :
http://katlas.math.toronto.edu/wiki/8_20
Example 2:
sage: L.regions([[-1, +2, -3, 4, +5, +1, -2, +6, +7, 3, -4, -7, -6,-5],['-','-','-','-','+','-','+']])
[[4, -11],
[2, -7],
[6, -1],
[13, 9],
[-4, -10, -12],
[-8, -2, -6, -14],
[10, -3, 8, -13],
[14, -5, 12, -9],
[7, 3, 11, 5, 1]]
sage: L.seifert_circles([[-1, +2, -3, 4, +5, +1, -2, +6, +7, 3, -4, -7, -6,-5],['-','-','-','-','+','-','+']])
[[9, 13, 9], [4, 12, 10, 4], [2, 8, 14, 6, 2], [1, 7, 3, 11, 5, 1]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment