Created
June 1, 2014 19:07
-
-
Save amitjamadagni/d039dd95b8e9733d66bb to your computer and use it in GitHub Desktop.
Braid to DT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dt_code(self): | |
r""" | |
Returns the dt_code | |
INPUT: | |
- Either a braidword, gauss_code, dt_code | |
OUTPUT: | |
- DT Code representation of the INPUT | |
EXAMPLES:: | |
""" | |
if self._dt_code != None: | |
return self._dt_code | |
elif self._braid != None: | |
b = list(self._braid.Tietze()) | |
N = len(b) | |
#b1 = [abs(x) for x in b] | |
#b1 = max(b1) | |
label = [0 for i in range(2*N)] | |
string = 1 | |
next_label = 1 | |
type1 = 0 | |
crossing = 0 | |
while(next_label <= 2*N): | |
string_found = 0 | |
for i in range(crossing, N): | |
if(abs(b[i]) == string or abs(b[i]) == string - 1): | |
string_found = 1 | |
crossing = i | |
break | |
if(string_found == 0): | |
for i in range(0,crossing): | |
if(abs(b[i]) == string or abs(b[i]) == string - 1): | |
string_found = 1 | |
crossing = i | |
break | |
if(label[2*crossing + next_label%2] == 1): | |
return "error" | |
else: | |
label[2*crossing + next_label%2] = next_label | |
next_label = next_label + 1 | |
if(type1 == 0): | |
if(b[crossing] < 0): | |
type1 = 1 | |
else: | |
type1 = -1 | |
else: | |
type1 = -1 * type1 | |
if((abs(b[crossing]) == string and b[crossing] * type1 > 0) or (abs(b[crossing]) != string and b[crossing] * type1 < 0)): | |
if(next_label%2 == 1): | |
label[2*crossing] = label[2*crossing] * -1 | |
if(abs(b[crossing]) == string): | |
string = string + 1 | |
else: | |
string = string - 1 | |
crossing = crossing + 1 | |
code = [0 for i in range(N)] | |
for i in range(N): | |
for j in range(N): | |
if label[2*j+1] == 2*i+1: | |
code[i] = label[2*j] | |
break | |
return code | |
elif self._gauss_code != None: | |
return "Not Implemented Error" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment