Skip to content

Commit 7df0790

Browse files
committed
Direct_Permute
1 parent be0f523 commit 7df0790

File tree

1 file changed

+17
-28
lines changed

1 file changed

+17
-28
lines changed

src/sage/geometry/lattice_polytope.py

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3194,12 +3194,11 @@ def PGE(S, u, v):
31943194
return S.one()
31953195
return S((u, v), check=False)
31963196

3197-
PM_old = self.vertex_facet_pairing_matrix()
3198-
n_v = PM_old.ncols()
3199-
n_f = PM_old.nrows()
3197+
PM = self.vertex_facet_pairing_matrix()
3198+
n_v = PM.ncols()
3199+
n_f = PM.nrows()
32003200
S_v = SymmetricGroup(n_v)
32013201
S_f = SymmetricGroup(n_f)
3202-
PM = PermutedMatrixWindow(PM_old, 0, 0, n_f, n_v)
32033202

32043203
# and find all the ways of making the first row of PM_max
32053204
def index_of_max(iterable):
@@ -3213,9 +3212,7 @@ def index_of_max(iterable):
32133212
n_s = 1
32143213
permutations = {0 : [S_f.one(), S_v.one()]}
32153214
for j in range(n_v):
3216-
m = index_of_max(
3217-
[(PM.with_permuted_columns(permutations[0][1]))[0][i]
3218-
for i in range(j, n_v)])
3215+
m = index_of_max([PM[0][i] for i in range(j, n_v)])
32193216
if m > 0:
32203217
permutations[0][1] = PGE(S_v, j + 1, m + j + 1) * permutations[0][1]
32213218
first_row = list(PM[0])
@@ -3224,25 +3221,23 @@ def index_of_max(iterable):
32243221
for k in range(1, n_f):
32253222
# Error for k == 1 already!
32263223
permutations[n_s] = [S_f.one(), S_v.one()]
3227-
m = index_of_max(PM.with_permuted_columns(permutations[n_s][1])[k])
3224+
m = index_of_max(PM[k, tuple((permutations[n_s][1].inverse())(j+1)-1 for j in range(n_v))])
32283225
if m > 0:
32293226
permutations[n_s][1] = PGE(S_v, 1, m+1) * permutations[n_s][1]
3230-
d = ((PM.with_permuted_columns(permutations[n_s][1]))[k][0]
3227+
d = (PM[k, (permutations[n_s][1].inverse())(1)-1]
32313228
- permutations[0][1](first_row)[0])
32323229
if d < 0:
32333230
# The largest elt of this row is smaller than largest elt
32343231
# in 1st row, so nothing to do
32353232
continue
32363233
# otherwise:
32373234
for i in range(1, n_v):
3238-
m = index_of_max(
3239-
[PM.with_permuted_columns(permutations[n_s][1])[k][j]
3240-
for j in range(i, n_v)])
3235+
m = index_of_max(PM[k, tuple((permutations[n_s][1].inverse())(j+1)-1 for j in range(i,n_v))])
32413236
if m > 0:
32423237
permutations[n_s][1] = PGE(S_v, i + 1, m + i + 1) \
32433238
* permutations[n_s][1]
32443239
if d == 0:
3245-
d = (PM.with_permuted_columns(permutations[n_s][1])[k][i]
3240+
d = (PM[k, (permutations[n_s][1].inverse())(i+1)-1]
32463241
-permutations[0][1](first_row)[i])
32473242
if d < 0:
32483243
break
@@ -3262,7 +3257,7 @@ def index_of_max(iterable):
32623257
n_s = 1
32633258
permutations = {k:permutations[k] for k in permutations if k < n_s}
32643259

3265-
b = PM.with_permuted_rows_and_columns(*permutations[0])[0]
3260+
b = tuple(PM[(permutations[0][0].inverse())(1)-1, (permutations[0][1].inverse())(j+1)-1] for j in range(n_v))
32663261
# Work out the restrictions the current permutations
32673262
# place on other permutations as a automorphisms
32683263
# of the first row
@@ -3296,20 +3291,17 @@ def index_of_max(iterable):
32963291
# between 0 and S(0)
32973292
for s in range(l, n_f):
32983293
for j in range(1, S[0]):
3299-
v = PM.with_permuted_rows_and_columns(
3300-
*permutations_bar[n_p])[s]
3294+
v = tuple(PM[(permutations_bar[n_p][0].inverse())(s+1)-1, (permutations_bar[n_p][1].inverse())(j+1)-1] for j in range(n_v))
33013295
if v[0] < v[j]:
33023296
permutations_bar[n_p][1] = PGE(S_v, 1, j + 1) * permutations_bar[n_p][1]
33033297
if ccf == 0:
3304-
l_r[0] = PM.with_permuted_rows_and_columns(
3305-
*permutations_bar[n_p])[s][0]
3298+
l_r[0] = PM[(permutations_bar[n_p][0].inverse())(s+1)-1, (permutations_bar[n_p][1].inverse())(1)-1]
33063299
permutations_bar[n_p][0] = PGE(S_f, l + 1, s + 1) * permutations_bar[n_p][0]
33073300
n_p += 1
33083301
ccf = 1
33093302
permutations_bar[n_p] = copy(permutations[k])
33103303
else:
3311-
d1 = PM.with_permuted_rows_and_columns(
3312-
*permutations_bar[n_p])[s][0]
3304+
d1 = PM[(permutations_bar[n_p][0].inverse())(s+1)-1, (permutations_bar[n_p][1].inverse())(1)-1]
33133305
d = d1 - l_r[0]
33143306
if d < 0:
33153307
# We move to the next line
@@ -3345,18 +3337,15 @@ def index_of_max(iterable):
33453337
s -= 1
33463338
# Find the largest value in this symmetry block
33473339
for j in range(c + 1, h):
3348-
v = PM.with_permuted_rows_and_columns(
3349-
*permutations_bar[s])[l]
3340+
v = tuple(PM[(permutations_bar[s][0].inverse())(l+1)-1, (permutations_bar[s][1].inverse())(j+1)-1] for j in range(n_v))
33503341
if (v[c] < v[j]):
33513342
permutations_bar[s][1] = PGE(S_v, c + 1, j + 1) * permutations_bar[s][1]
33523343
if ccf == 0:
33533344
# Set reference and carry on to next permutation
3354-
l_r[c] = PM.with_permuted_rows_and_columns(
3355-
*permutations_bar[s])[l][c]
3345+
l_r[c] = PM[(permutations_bar[s][0].inverse())(l+1)-1, (permutations_bar[s][1].inverse())(c+1)-1]
33563346
ccf = 1
33573347
else:
3358-
d1 = PM.with_permuted_rows_and_columns(
3359-
*permutations_bar[s])[l][c]
3348+
d1 = PM[(permutations_bar[s][0].inverse())(l+1)-1, (permutations_bar[s][1].inverse())(c+1)-1]
33603349
d = d1 - l_r[c]
33613350
if d < 0:
33623351
n_p -= 1
@@ -3385,7 +3374,7 @@ def index_of_max(iterable):
33853374
# the restrictions the last worked out
33863375
# row imposes.
33873376
c = 0
3388-
M = (PM.with_permuted_rows_and_columns(*permutations[0]))[l]
3377+
M = tuple(PM[(permutations[0][0].inverse())(l+1)-1, (permutations[0][1].inverse())(j+1)-1] for j in range(n_v))
33893378
while c < n_v:
33903379
s = S[c] + 1
33913380
S[c] = c + 1
@@ -3398,7 +3387,7 @@ def index_of_max(iterable):
33983387
S[c] = c + 1
33993388
c += 1
34003389
# Now we have the perms, we construct PM_max using one of them
3401-
PM_max = PM_old.with_permuted_rows_and_columns(*permutations[0])
3390+
PM_max = PM.with_permuted_rows_and_columns(*permutations[0])
34023391
if check:
34033392
return (PM_max, permutations)
34043393
else:

0 commit comments

Comments
 (0)