Skip to content

Commit 5f2a820

Browse files
committed
Still permutation
1 parent 8085a00 commit 5f2a820

File tree

1 file changed

+42
-41
lines changed

1 file changed

+42
-41
lines changed

src/sage/geometry/lattice_polytope.py

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3209,54 +3209,54 @@ def index_of_max(iterable):
32093209
return m
32103210

32113211
n_s = 1
3212-
permutations_inv = {0: [S_f.one(), S_v.one()]}
3212+
permutations = {0: [S_f.one(), S_v.one()]}
32133213
for j in range(n_v):
32143214
m = index_of_max([PM[0][i] for i in range(j, n_v)])
32153215
if m > 0:
3216-
permutations_inv[0][1] = permutations_inv[0][1] * PGE(S_v, j + 1, m + j + 1)
3216+
permutations[0][1] = PGE(S_v, j + 1, m + j + 1) * permutations[0][1]
32173217
first_row = list(PM[0])
32183218

32193219
# Arrange other rows one by one and compare with first row
32203220
for k in range(1, n_f):
32213221
# Error for k == 1 already!
3222-
permutations_inv[n_s] = [S_f.one(), S_v.one()]
3223-
m = index_of_max(tuple(PM[k, permutations_inv[n_s][1](j+1) - 1] for j in range(n_v)))
3222+
permutations[n_s] = [S_f.one(), S_v.one()]
3223+
m = index_of_max(tuple(PM[k, permutations[n_s][1](j+1) - 1] for j in range(n_v)))
32243224
if m > 0:
3225-
permutations_inv[n_s][1] = permutations_inv[n_s][1] * PGE(S_v, 1, m+1)
3226-
d = (PM[k, permutations_inv[n_s][1](1) - 1]
3227-
- (permutations_inv[0][1].inverse())(first_row)[0])
3225+
permutations[n_s][1] = PGE(S_v, 1, m+1) * permutations[n_s][1]
3226+
d = (PM[k, permutations[n_s][1](1) - 1]
3227+
- permutations[0][1](first_row)[0])
32283228
if d < 0:
32293229
# The largest elt of this row is smaller than largest elt
32303230
# in 1st row, so nothing to do
32313231
continue
32323232
# otherwise:
32333233
for i in range(1, n_v):
3234-
m = index_of_max(tuple(PM[k, permutations_inv[n_s][1](j+1) - 1] for j in range(i,n_v)))
3234+
m = index_of_max(tuple(PM[k, permutations[n_s][1](j+1) - 1] for j in range(i,n_v)))
32353235
if m > 0:
3236-
permutations_inv[n_s][1] = permutations_inv[n_s][1] \
3237-
* PGE(S_v, i + 1, m + i + 1)
3236+
permutations[n_s][1] = PGE(S_v, i + 1, m + i + 1) \
3237+
* permutations[n_s][1]
32383238
if d == 0:
3239-
d = (PM[k, permutations_inv[n_s][1](i+1) - 1]
3240-
-(permutations_inv[0][1].inverse())(first_row)[i])
3239+
d = (PM[k, permutations[n_s][1](i+1) - 1]
3240+
-permutations[0][1](first_row)[i])
32413241
if d < 0:
32423242
break
32433243
if d < 0:
32443244
# This row is smaller than 1st row, so nothing to do
3245-
del permutations_inv[n_s]
3245+
del permutations[n_s]
32463246
continue
3247-
permutations_inv[n_s][0] = permutations_inv[n_s][0] * PGE(S_f, 1, k + 1)
3247+
permutations[n_s][0] = PGE(S_f, 1, k + 1) * permutations[n_s][0]
32483248
if d == 0:
32493249
# This row is the same, so we have a symmetry!
32503250
n_s += 1
32513251
else:
32523252
# This row is larger, so it becomes the first row and
32533253
# the symmetries reset.
32543254
first_row = list(PM[k])
3255-
permutations_inv = {0: permutations_inv[n_s]}
3255+
permutations = {0: permutations[n_s]}
32563256
n_s = 1
3257-
permutations_inv = {k: permutations_inv[k] for k in permutations_inv if k < n_s}
3257+
permutations = {k: permutations[k] for k in permutations if k < n_s}
32583258

3259-
b = tuple(PM[permutations_inv[0][0](1) - 1, permutations_inv[0][1](j+1) - 1] for j in range(n_v))
3259+
b = tuple(PM[permutations[0][0](1) - 1, permutations[0][1](j+1) - 1] for j in range(n_v))
32603260
# Work out the restrictions the current permutations
32613261
# place on other permutations as a automorphisms
32623262
# of the first row
@@ -3274,7 +3274,7 @@ def index_of_max(iterable):
32743274
# We determine the other rows of PM_max in turn by use of perms and
32753275
# aut on previous rows.
32763276
for l in range(1, n_f - 1):
3277-
n_s = len(permutations_inv)
3277+
n_s = len(permutations)
32783278
n_s_bar = n_s
32793279
cf = 0
32803280
l_r = [0]*n_v
@@ -3284,42 +3284,42 @@ def index_of_max(iterable):
32843284
# number of local permutations associated with current global
32853285
n_p = 0
32863286
ccf = cf
3287-
permutations_inv_bar = {0: copy(permutations_inv[k])}
3287+
permutations_bar = {0: copy(permutations[k])}
32883288
# We look for the line with the maximal entry in the first
32893289
# subsymmetry block, i.e. we are allowed to swap elements
32903290
# between 0 and S(0)
32913291
for s in range(l, n_f):
32923292
for j in range(1, S[0]):
3293-
v = tuple(PM[permutations_inv_bar[n_p][0](s+1) - 1, permutations_inv_bar[n_p][1](j+1) - 1] for j in range(n_v))
3293+
v = tuple(PM[permutations_bar[n_p][0](s+1) - 1, permutations_bar[n_p][1](i+1) - 1] for i in range(n_v))
32943294
if v[0] < v[j]:
3295-
permutations_inv_bar[n_p][1] = permutations_inv_bar[n_p][1] * PGE(S_v, 1, j + 1)
3295+
permutations_bar[n_p][1] = PGE(S_v, 1, j + 1) * permutations_bar[n_p][1]
32963296
if ccf == 0:
3297-
l_r[0] = PM[permutations_inv_bar[n_p][0](s+1) - 1, permutations_inv_bar[n_p][1](1) - 1]
3298-
permutations_inv_bar[n_p][0] = permutations_inv_bar[n_p][0] * PGE(S_f, l + 1, s + 1)
3297+
l_r[0] = PM[permutations_bar[n_p][0](s+1) - 1, permutations_bar[n_p][1](1) - 1]
3298+
permutations_bar[n_p][0] = PGE(S_f, l + 1, s + 1) * permutations_bar[n_p][0]
32993299
n_p += 1
33003300
ccf = 1
3301-
permutations_inv_bar[n_p] = copy(permutations_inv[k])
3301+
permutations_bar[n_p] = copy(permutations[k])
33023302
else:
3303-
d1 = PM[permutations_inv_bar[n_p][0](s+1) - 1, permutations_inv_bar[n_p][1](1) - 1]
3303+
d1 = PM[permutations_bar[n_p][0](s+1) - 1, permutations_bar[n_p][1](1) - 1]
33043304
d = d1 - l_r[0]
33053305
if d < 0:
33063306
# We move to the next line
33073307
continue
33083308
elif d==0:
33093309
# Maximal values agree, so possible symmetry
3310-
permutations_inv_bar[n_p][0] = permutations_inv_bar[n_p][0] * PGE(S_f, l + 1, s + 1)
3310+
permutations_bar[n_p][0] = PGE(S_f, l + 1, s + 1) * permutations_bar[n_p][0]
33113311
n_p += 1
3312-
permutations_inv_bar[n_p] = copy(permutations_inv[k])
3312+
permutations_bar[n_p] = copy(permutations[k])
33133313
else:
33143314
# We found a greater maximal value for first entry.
33153315
# It becomes our new reference:
33163316
l_r[0] = d1
3317-
permutations_inv_bar[n_p][0] = permutations_inv_bar[n_p][0] * PGE(S_f, l + 1, s + 1)
3317+
permutations_bar[n_p][0] = PGE(S_f, l + 1, s + 1) * permutations_bar[n_p][0]
33183318
# Forget previous work done
33193319
cf = 0
3320-
permutations_inv_bar = {0:copy(permutations_inv_bar[n_p])}
3320+
permutations_bar = {0:copy(permutations_bar[n_p])}
33213321
n_p = 1
3322-
permutations_inv_bar[n_p] = copy(permutations_inv[k])
3322+
permutations_bar[n_p] = copy(permutations[k])
33233323
n_s = k + 1
33243324
# Check if the permutations found just now work
33253325
# with other elements
@@ -3336,20 +3336,21 @@ def index_of_max(iterable):
33363336
s -= 1
33373337
# Find the largest value in this symmetry block
33383338
for j in range(c + 1, h):
3339-
v = tuple(PM[(permutations_inv_bar[s][0])(l+1) - 1, (permutations_inv_bar[s][1])(j+1) - 1] for j in range(n_v))
3339+
v = tuple(PM[(permutations_bar[s][0])(l+1) - 1, (permutations_bar[s][1])(i+1) - 1] for i in range(n_v))
3340+
print(v)
33403341
if (v[c] < v[j]):
3341-
permutations_inv_bar[s][1] = permutations_inv_bar[s][1] * PGE(S_v, c + 1, j + 1)
3342+
permutations_bar[s][1] = PGE(S_v, c + 1, j + 1) * permutations_bar[s][1]
33423343
if ccf == 0:
33433344
# Set reference and carry on to next permutation
3344-
l_r[c] = PM[(permutations_inv_bar[s][0])(l+1) - 1, (permutations_inv_bar[s][1])(c+1) - 1]
3345+
l_r[c] = PM[(permutations_bar[s][0])(l+1) - 1, (permutations_bar[s][1])(c+1) - 1]
33453346
ccf = 1
33463347
else:
3347-
d1 = PM[(permutations_inv_bar[s][0])(l+1) - 1, (permutations_inv_bar[s][1])(c+1) - 1]
3348+
d1 = PM[(permutations_bar[s][0])(l+1) - 1, (permutations_bar[s][1])(c+1) - 1]
33483349
d = d1 - l_r[c]
33493350
if d < 0:
33503351
n_p -= 1
33513352
if s < n_p:
3352-
permutations_inv_bar[s] = copy(permutations_inv_bar[n_p])
3353+
permutations_bar[s] = copy(permutations_bar[n_p])
33533354
elif d > 0:
33543355
# The current case leads to a smaller matrix,
33553356
# hence this case becomes our new reference
@@ -3359,21 +3360,21 @@ def index_of_max(iterable):
33593360
n_s = k + 1
33603361
# Update permutations
33613362
if (n_s - 1) > k:
3362-
permutations_inv[k] = copy(permutations_inv[n_s - 1])
3363+
permutations[k] = copy(permutations[n_s - 1])
33633364
n_s -= 1
33643365
for s in range(n_p):
3365-
permutations_inv[n_s] = copy(permutations_inv_bar[s])
3366+
permutations[n_s] = copy(permutations_bar[s])
33663367
n_s += 1
33673368
cf = n_s
3368-
permutations_inv = {k: permutations_inv[k] for k in permutations_inv if k < n_s}
3369+
permutations = {k: permutations[k] for k in permutations if k < n_s}
33693370
# If the automorphisms are not already completely restricted,
33703371
# update them
33713372
if S != list(range(1, n_v + 1)):
33723373
# Take the old automorphisms and update by
33733374
# the restrictions the last worked out
33743375
# row imposes.
33753376
c = 0
3376-
M = tuple(PM[permutations_inv[0][0](l+1) - 1, permutations_inv[0][1](j+1) - 1] for j in range(n_v))
3377+
M = tuple(PM[permutations[0][0](l+1) - 1, permutations[0][1](j+1) - 1] for j in range(n_v))
33773378
while c < n_v:
33783379
s = S[c] + 1
33793380
S[c] = c + 1
@@ -3386,9 +3387,9 @@ def index_of_max(iterable):
33863387
S[c] = c + 1
33873388
c += 1
33883389
# Now we have the perms, we construct PM_max using one of them
3389-
PM_max = PM.with_permuted_rows_and_columns(permutations_inv[0][0].inverse(), permutations_inv[0][1].inverse())
3390+
PM_max = PM.with_permuted_rows_and_columns(*permutations[0])
33903391
if check:
3391-
return (PM_max, {p: [permutations_inv[p][0].inverse(),permutations_inv[p][1].inverse()] for p in permutations_inv.keys()})
3392+
return (PM_max, permutations)
33923393
else:
33933394
return PM_max
33943395

0 commit comments

Comments
 (0)