-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_cactus.py
217 lines (200 loc) · 7.64 KB
/
test_cactus.py
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
"""
test for cactus group
"""
#pylint:disable=invalid-name,too-many-locals,import-error
from typing import Tuple, Dict
from cactus import CactusGroup, Permutation, VirtualCactusGroup, perm_multiply
def test_gen_rel_cactus() -> None:
"""
check the generators and relations of J_10
"""
MY_N = 10
s_gens: Dict[Tuple[int, int], CactusGroup] = {}
iden = CactusGroup(MY_N)
# define the generators
for p in range(1, MY_N):
for q in range(p+1, MY_N+1):
current_gen = CactusGroup(MY_N)
current_gen.append_generator(p, q)
s_gens[(p, q)] = current_gen
# check the relations and
# check that to_permutation
# obeys the defining relations
for p in range(1, MY_N):
for q in range(p+1, MY_N+1):
spq = s_gens[(p, q)]
assert spq*spq == iden
pi_pq = spq.to_permutation()
for idx in range(0, p-1):
assert pi_pq[idx] == idx+1, f"{p} {q} {pi_pq} {idx}"
for idx in range(q, spq.index):
assert pi_pq[idx] == idx+1, f"{p} {q} {pi_pq} {idx}"
for idx in range(p-1, q):
assert pi_pq[idx] == q-(idx-p+1), f"{p} {q} {pi_pq} {idx}"
assert perm_multiply(pi_pq, pi_pq) == iden.to_permutation()
for k in range(q+1, MY_N):
for l in range(k+1, MY_N+1):
skl = s_gens[(k, l)]
pi_kl = skl.to_permutation()
assert spq*skl == skl*spq
assert perm_multiply(
pi_pq, pi_kl) == perm_multiply(pi_kl, pi_pq)
for k in range(p, MY_N):
for l in range(k+1, q+1):
skl = s_gens[(k, l)]
pi_kl = skl.to_permutation()
s_messy = s_gens[(p+q-l, p+q-k)]
pi_messy = s_messy.to_permutation()
assert spq*skl == s_messy*spq
lhs = perm_multiply(pi_pq, pi_kl)
rhs = perm_multiply(pi_messy, pi_pq)
assert lhs == rhs
def test_vCactus() -> None:
"""
check the generators and relations of J_10 included into vJ_10
"""
MY_N = 10
s_gens: Dict[Tuple[int, int], VirtualCactusGroup] = {}
iden = VirtualCactusGroup(MY_N)
# define the generators
for p in range(1, MY_N):
for q in range(p+1, MY_N+1):
current_gen = CactusGroup(MY_N)
current_gen.append_generator(p, q)
current_vgen = iden*current_gen
s_gens[(p, q)] = current_vgen
# check the relations and
# check that to_permutation
# obeys the defining relations
for p in range(1, MY_N):
for q in range(p+1, MY_N+1):
spq = s_gens[(p, q)]
lhs = spq*spq
assert lhs == iden, f"{str(spq)} and {str(iden)}"
for k in range(q+1, MY_N):
for l in range(k+1, MY_N+1):
skl = s_gens[(k, l)]
lhs = spq*skl
rhs = skl*spq
str1 = str(lhs)
str2 = str(rhs)
assert lhs == rhs, f"{str1} and {str2}"
for k in range(p, MY_N):
for l in range(k+1, q+1):
skl = s_gens[(k, l)]
s_messy = s_gens[(p+q-l, p+q-k)]
assert spq*skl == s_messy*spq
def test_perm_promoted() -> None:
"""
S_10 included into vJ_10
"""
MY_N = 10
perm_1 = Permutation.random(MY_N)
perm_2 = Permutation.random(MY_N)
perm_1_promoted = VirtualCactusGroup(MY_N)
perm_1_promoted *= perm_1
perm_2_promoted = VirtualCactusGroup(MY_N)
perm_2_promoted *= perm_2
perm_12_promoted = VirtualCactusGroup(MY_N)
perm_12_promoted *= (perm_1*perm_2)
assert perm_1_promoted*perm_2_promoted == perm_12_promoted
#pylint:disable=too-many-branches,too-many-statements
def test_cross_rels() -> None:
"""
the defining ws_ijw^-1 = s_wi,wj relations in vJ_5
"""
MY_N = 5
s_gens: Dict[Tuple[int, int], VirtualCactusGroup] = {}
iden = VirtualCactusGroup(MY_N)
# define the s_ij
for p in range(1, MY_N):
for q in range(p+1, MY_N+1):
current_gen = CactusGroup(MY_N)
current_gen.append_generator(p, q)
current_vgen = iden*current_gen
s_gens[(p, q)] = current_vgen
perm_1 = Permutation.random(MY_N)
perm_1_promoted = VirtualCactusGroup(MY_N)
perm_1_promoted *= perm_1
for p in range(1, MY_N):
for q in range(p+1, MY_N+1):
maybe_k_shift = perm_1.preserves_intervalness(p,q)
if maybe_k_shift is None:
continue
expected_rhs = VirtualCactusGroup(MY_N)
expected_rhs_cactus = s_gens[(p+maybe_k_shift,q+maybe_k_shift)]
expected_rhs *= expected_rhs_cactus
spq = s_gens[(p, q)]
lhs = perm_1_promoted*spq
lhs /= perm_1_promoted
assert lhs==expected_rhs
perm_1.element = list(range(1,MY_N+1))
perm_1.element[0], perm_1.element[1] = perm_1.element[1], perm_1.element[0]
perm_1_promoted = VirtualCactusGroup(MY_N)
perm_1_promoted *= perm_1
for p in range(1, MY_N):
for q in range(p+1, MY_N+1):
maybe_k_shift = perm_1.preserves_intervalness(p,q)
#pylint:disable=no-else-continue
if maybe_k_shift is None:
#pylint:disable=consider-using-in
assert p==1 or p==2
continue
else:
assert p>2
assert maybe_k_shift == 0
expected_rhs = VirtualCactusGroup(MY_N)
expected_rhs_cactus = s_gens[(p+maybe_k_shift,q+maybe_k_shift)]
expected_rhs *= expected_rhs_cactus
spq = s_gens[(p, q)]
lhs = perm_1_promoted*spq
lhs /= perm_1_promoted
assert lhs==expected_rhs
perm_1.element = list(range(3,MY_N+3))
perm_1.element[-1] = 2
perm_1.element[-2] = 1
perm_1_promoted = VirtualCactusGroup(MY_N)
perm_1_promoted *= perm_1
for p in range(1, MY_N):
for q in range(p+1, MY_N+1):
maybe_k_shift = perm_1.preserves_intervalness(p,q)
#pylint:disable=no-else-continue
if maybe_k_shift is None:
continue
else:
#pylint:disable=consider-using-in
assert maybe_k_shift == 2 or maybe_k_shift == -3
expected_rhs = VirtualCactusGroup(MY_N)
expected_rhs_cactus = s_gens[(p+maybe_k_shift,q+maybe_k_shift)]
expected_rhs *= expected_rhs_cactus
spq = s_gens[(p, q)]
lhs = perm_1_promoted*spq
lhs /= perm_1_promoted
assert lhs==expected_rhs
def test_random_iden() -> None:
"""
produce a random element of vJ_4 and check that
x*x^-1 gives identity
"""
MY_N = 4
iden_perm = Permutation(MY_N)
iden_cact = CactusGroup(MY_N)
iden_v = VirtualCactusGroup(MY_N)
for my_len in range(7):
lhs = CactusGroup.random(MY_N,my_len)
lhs *= lhs.inv()
assert lhs.to_permutation() == iden_perm.element, f"{lhs}"
if lhs != iden_cact:
lhs.simplify()
assert lhs == iden_cact, f"{lhs}"
for _ in range(10):
lhs_perm = Permutation.random(MY_N)
lhs_perm *= lhs_perm.inv()
assert lhs_perm == iden_perm, f"{lhs_perm}"
MY_CACT_LEN = 6
for my_len in [0,1,2]:
lhs_vcact = VirtualCactusGroup.random(MY_N,MY_CACT_LEN,my_len)
lhs_vcact *= lhs_vcact.inv()
if lhs_vcact != iden_v:
# it might not simplify all the way to identity
print(f"{lhs_vcact} with {my_len}")