forked from jeanluct/cbraid
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlibrary.pyx
286 lines (240 loc) · 7.69 KB
/
library.pyx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#clang C++
#clib braiding
r"""
Cython wrapper for the libbraiding library.
The libbraiding library is a modification of the braiding program
by Juan Gonzalez-Meneses (https://github.com/jeanluct/cbraid)
to expose the functions as a C++ library instead of an interactive
program.
Braids are returned in left normal form as a list of lists. The
first list contains only an integer, representing the power of
Delta. The subsequent lists are the Tietze lists of the elementary
permutation braids.
"""
from cysignals.signals cimport sig_on, sig_off
from libcpp.list cimport list
cdef extern from "braiding.h" namespace "Braiding":
list[list[int]] ConjugatingBraid (int n, list[int] word, list[int] word2)
list[list[int]] LeftNormalForm (int n, list[int] word)
list[list[int]] RightNormalForm (int n, list[int] word)
list[list[int]] GreatestCommonDivisor(int n, list[int] word1, list[int] word2)
list[list[int]] LeastCommonMultiple(int n, list[int] word1, list[int] word2)
list[list[list[int]]] CentralizerGenerators(int n, list[int] word)
list[list[list[int]]] SuperSummitSet(int n, list[int] word)
list[list[list[list[int]]]] UltraSummitSet(int n, list[int] word)
int thurstontype(int n, list[int] word);
int Rigidity_ext(int n, list[int] word);
list[list[list[list[int]]]] SlidingCircuits(int n, list[int] word)
list[list[list[int]]] SendToSSS(int n, list[int] word)
list[list[list[int]]] SendToUSS(int n, list[int] word)
list[list[list[int]]] SendToSC(int n, list[int] word)
list[list[list[int]]] Trajectory(int n, list[int] word)
list[list[list[list[int]]]] CyclicSlidings(int n, list[int] word)
def conjugatingbraid(braid1, braid2):
r"""
Return a braid that conjugates braid1 to braid2, if such a braid exists.
INPUT:
- ``braid1`` -- the braid to be conjugated.
- ``braid2`` -- the braid to conjugate to.
OUTPUT:
The list of lists that represent a conjugating braid. If the input braids
are not conjugate, an empty list is returned.
EXAMPLES::
sage: B = BraidGroup(3)
sage: b = B([1,2,1,-2])
sage: c = B([1,2])
sage: conjugatingbraid(b,c) # optional - libbraiding
[[0], [2]]
"""
nstrands = max(braid1.parent().strands(), braid2.parent().strands())
l1 = braid1.Tietze()
l2 = braid2.Tietze()
sig_on()
cdef list[list[int]] rop = ConjugatingBraid(nstrands, l1, l2)
sig_off()
return rop
def leftnormalform(braid):
r"""
Return the left normal form of a braid.
INPUT:
- ``braid`` -- a braid
OUTPUT:
A list of lists with the left normal form. The first list contains the
power of delta. The subsequent lists are the elementary permutation braids.
EXAMPLES::
sage: B = BraidGroup(3)
sage: b = B([1,2,1,-2])
sage: leftnormalform(b) # optional - libbraiding
[[0], [2, 1]]
"""
nstrands = braid.parent().strands()
l1 = braid.Tietze()
sig_on()
cdef list[list[int]] rop = LeftNormalForm(nstrands, l1)
sig_off()
return rop
def rightnormalform(braid):
r"""
Return the right normal form of a braid.
INPUT:
- ``braid`` -- a braid
OUTPUT:
A list of lists with the right normal form. The first list contains the
power of delta. The subsequent lists are the elementary permutation braids.
EXAMPLES::
sage: B = BraidGroup(3)
sage: b = B([1,2,1,-2])
sage: rightnormalform(b) # optional - libbraiding
[[2, 1], [0]]
"""
nstrands = braid.parent().strands()
l1 = braid.Tietze()
sig_on()
cdef list[list[int]] rop = RightNormalForm(nstrands, l1)
sig_off()
return rop
def greatestcommondivisor(braid1, braid2):
r"""
Return the greatest common divisor of two braids.
"""
nstrands = max(braid1.parent().strands(), braid2.parent().strands())
l1 = braid1.Tietze()
l2 = braid2.Tietze()
sig_on()
cdef list[list[int]] rop = GreatestCommonDivisor(nstrands, l1, l2)
sig_off()
return rop
def leastcommonmultiple(braid1, braid2):
r"""
Return the least common multiple of two braids.
"""
nstrands = max(braid1.parent().strands(), braid2.parent().strands())
l1 = braid1.Tietze()
l2 = braid2.Tietze()
sig_on()
cdef list[list[int]] rop = LeastCommonMultiple(nstrands, l1, l2)
sig_off()
return rop
def centralizer(braid):
r"""
Return a list of generators of the centralizer of a braid.
"""
nstrands = braid.parent().strands()
lnf = leftnormalform(braid)
if len(lnf) == 1: # (lib)braiding crashes when the input is a power of Delta.
if lnf[0][0] % 2 == 0:
return [[[0], [i+1]] for i in range(nstrands)]
elif nstrands % 2:
return [[[0], [i+1, nstrands - i -1]] for i in range(nstrands/2)]
else:
return [[[0], [i+1, nstrands - i -1]] for i in range(nstrands/2-1)] + [[[0], [nstrands/2]]]
l = braid.Tietze()
sig_on()
cdef list[list[list[int]]] rop = CentralizerGenerators(nstrands, l)
sig_off()
return rop
def supersummitset(braid):
r"""
Return a list with the super-summit-set of a braid.
"""
nstrands = braid.parent().strands()
l = braid.Tietze()
sig_on()
cdef list[list[list[int]]] rop = SuperSummitSet(nstrands, l)
sig_off()
return rop
def ultrasummitset(braid):
r"""
Return a list with the ultra-summit-set of the braid.
"""
nstrands = braid.parent().strands()
l = braid.Tietze()
sig_on()
cdef list[list[list[list[int]]]] rop = UltraSummitSet(nstrands, l)
sig_off()
return rop
def thurston_type(braid):
r"""
Return the Thurston type of the braid
"""
nstrands = braid.parent().strands()
l = braid.Tietze()
sig_on()
cdef int i = thurstontype(nstrands, l)
sig_off()
if i == 1:
return 'periodic'
elif i==2:
return 'reducible'
elif i==3:
return 'pseudo-anosov'
def rigidity(braid):
r"""
Return the rigidity of the braid
"""
nstrands = braid.parent().strands()
l = braid.Tietze()
sig_on()
cdef int i = Rigidity_ext(nstrands, l)
sig_off()
return i
def sliding_circuits(braid):
r"""
Return the set of sliding circuits of the braid
"""
nstrands = braid.parent().strands()
l = braid.Tietze()
sig_on()
cdef list[list[list[list[int]]]] rop = SlidingCircuits(nstrands, l)
sig_off()
return rop
def send_to_sss(braid):
r"""
Returns an element of the braid's SSS and the conjugating braid.
"""
nstrands = braid.parent().strands()
l = braid.Tietze()
sig_on()
cdef list[list[list[int]]] rop = SendToSSS(nstrands, l)
sig_off()
return rop
def send_to_uss(braid):
r"""
Returns an element of the braid's USS and the conjugating braid.
"""
nstrands = braid.parent().strands()
l = braid.Tietze()
sig_on()
cdef list[list[list[int]]] rop = SendToUSS(nstrands, l)
sig_off()
return rop
def send_to_sc(braid):
r"""
Returns an element of the braid's sliding circuits and the conjugating braid.
"""
nstrands = braid.parent().strands()
l = braid.Tietze()
sig_on()
cdef list[list[list[int]]] rop = SendToSC(nstrands, l)
sig_off()
return rop
def trajectory(braid):
r"""
Returns the trajectory of the braid
"""
nstrands = braid.parent().strands()
l = braid.Tietze()
sig_on()
cdef list[list[list[int]]] rop = Trajectory(nstrands, l)
sig_off()
return rop
def cyclic_slidings(braid):
r"""
Returns the braid's cyclic slidings
"""
nstrands = braid.parent().strands()
l = braid.Tietze()
sig_on()
cdef list[list[list[list[int]]]] rop = CyclicSlidings(nstrands, l)
sig_off()
return rop