Skip to content

Commit e33815f

Browse files
committed
pep8 and code details in weyl_characters.py
1 parent 27b077e commit e33815f

File tree

1 file changed

+55
-56
lines changed

1 file changed

+55
-56
lines changed

src/sage/combinat/root_system/weyl_characters.py

Lines changed: 55 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def __init__(self, ct, base_ring=ZZ, prefix=None, style="lattice", k=None, conju
125125
self._origin = self._space.zero()
126126
if prefix is None:
127127
if ct.is_atomic():
128-
prefix = ct[0]+str(ct[1])
128+
prefix = ct[0] + str(ct[1])
129129
else:
130130
prefix = repr(ct)
131131
self._prefix = prefix
@@ -510,7 +510,7 @@ def product_on_basis(self, a, b):
510510
# smaller character is the one that is decomposed
511511
# into weights.
512512
if sum(a.coefficients()) > sum(b.coefficients()):
513-
a,b = b,a
513+
a, b = b, a
514514
return self._product_helper(self._irr_weights(a), b)
515515

516516
def _product_helper(self, d1, b):
@@ -535,11 +535,11 @@ def _product_helper(self, d1, b):
535535
"""
536536
d = {}
537537
for k in d1:
538-
[epsilon,g] = self.dot_reduce(b+k)
538+
[epsilon, g] = self.dot_reduce(b + k)
539539
if epsilon == 1:
540-
d[g] = d.get(g,0) + d1[k]
540+
d[g] = d.get(g, 0) + d1[k]
541541
elif epsilon == -1:
542-
d[g] = d.get(g,0) - d1[k]
542+
d[g] = d.get(g, 0) - d1[k]
543543
return self._from_dict(d, coerce=True)
544544

545545
def dot_reduce(self, a):
@@ -576,31 +576,32 @@ def dot_reduce(self, a):
576576
return [0, self._space.zero()]
577577
elif c < -1:
578578
epsilon = -epsilon
579-
ret -= (1+c)*alpha[i]
579+
ret -= (1 + c) * alpha[i]
580580
done = False
581581
break
582582
if self._k is not None:
583583
l = self.level(ret)
584584
k = self._k
585585
if l > k:
586-
if l == k+1:
586+
if l == k + 1:
587587
return [0, self._space.zero()]
588588
else:
589589
epsilon = -epsilon
590-
ret = self.affine_reflect(ret,k+1)
590+
ret = self.affine_reflect(ret, k + 1)
591591
done = False
592592
return [epsilon, ret]
593593

594594
def affine_reflect(self, wt, k=0):
595595
r"""
596+
Return the reflection of wt in the hyperplane `\theta`.
597+
598+
Optionally, this also shifts by a multiple `k` of `\theta`.
599+
596600
INPUT:
597601
598602
- ``wt`` -- a weight
599603
- ``k`` -- (optional) a positive integer
600604
601-
Returns the reflection of wt in the hyperplane
602-
`\theta`. Optionally shifts by a multiple `k`of `\theta`.
603-
604605
EXAMPLES::
605606
606607
sage: B22 = FusionRing("B2",2)
@@ -609,8 +610,8 @@ def affine_reflect(self, wt, k=0):
609610
sage: [B22.affine_reflect(x,2) for x in fw]
610611
[(2, 1), (3/2, 3/2)]
611612
"""
612-
coef = ZZ(2*wt.inner_product(self._highest)/self._hip)
613-
return wt+(k-coef)*self._highest
613+
coef = ZZ(2 * wt.inner_product(self._highest) / self._hip)
614+
return wt + (k - coef) * self._highest
614615

615616
def some_elements(self):
616617
"""
@@ -722,7 +723,7 @@ def _demazure_helper(self, dd, word="long", debug=False):
722723
for i in index_set:
723724
temp = []
724725
cm[i] = [0] * r
725-
for ind,j in enumerate(index_set):
726+
for ind, j in enumerate(index_set):
726727
cm[i][ind] = int(alpha[i].inner_product(alphacheck[j]))
727728
if cm[i][ind]:
728729
temp.append(ind)
@@ -737,27 +738,27 @@ def _demazure_helper(self, dd, word="long", debug=False):
737738
print("i=%s" % i)
738739
next = {}
739740
for v in accum:
740-
coroot = v[i-1]
741+
coroot = v[i - 1]
741742
if debug:
742743
print(" v=%s, coroot=%s" % (v, coroot))
743744
if coroot >= 0:
744745
mu = v
745-
for j in range(coroot+1):
746-
next[mu] = next.get(mu,0) + accum[v]
746+
for j in range(coroot + 1):
747+
next[mu] = next.get(mu, 0) + accum[v]
747748
if debug:
748749
print(" mu=%s, next[mu]=%s" % (mu, next[mu]))
749750
mu = list(mu)
750-
for k in supp[i-1]:
751+
for k in supp[i - 1]:
751752
mu[k] -= cm[i][k]
752753
mu = tuple(mu)
753754
else:
754755
mu = v
755-
for j in range(-1-coroot):
756+
for j in range(-1 - coroot):
756757
mu = list(mu)
757-
for k in supp[i-1]:
758+
for k in supp[i - 1]:
758759
mu[k] += cm[i][k]
759760
mu = tuple(mu)
760-
next[mu] = next.get(mu,0) - accum[v]
761+
next[mu] = next.get(mu, 0) - accum[v]
761762
if debug:
762763
print(" mu=%s, next[mu]=%s" % (mu, next[mu]))
763764
accum = {}
@@ -789,9 +790,9 @@ def _weight_multiplicities(self, x):
789790
d1 = self._irr_weights(k)
790791
for l in d1:
791792
if l in d:
792-
d[l] += c*d1[l]
793+
d[l] += c * d1[l]
793794
else:
794-
d[l] = c*d1[l]
795+
d[l] = c * d1[l]
795796
for k in list(d):
796797
if d[k] == 0:
797798
del d[k]
@@ -824,7 +825,7 @@ def irr_repr(self, hwv):
824825
sage: [B3.irr_repr(v) for v in B3.fundamental_weights()]
825826
['B3(1,0,0)', 'B3(0,1,0)', 'B3(0,0,1)']
826827
"""
827-
return self._prefix+self._wt_repr(hwv)
828+
return self._prefix + self._wt_repr(hwv)
828829

829830
def level(self, wt):
830831
"""
@@ -838,7 +839,7 @@ def level(self, wt):
838839
sage: [CartanType("F4~").dual().a()[x] for x in [1..4]]
839840
[2, 3, 2, 1]
840841
"""
841-
return ZZ(2*wt.inner_product(self._highest)/self._hip)
842+
return ZZ(2 * wt.inner_product(self._highest) / self._hip)
842843

843844
def _dual_helper(self, wt):
844845
"""
@@ -857,7 +858,7 @@ def _dual_helper(self, wt):
857858
alphacheck = self._space.simple_coroots()
858859
fw = self._space.fundamental_weights()
859860
for i in self._space.index_set():
860-
ret += wt.inner_product(alphacheck[i])*fw[self._opposition[i]]
861+
ret += wt.inner_product(alphacheck[i]) * fw[self._opposition[i]]
861862
return ret
862863

863864
def _wt_repr(self, wt):
@@ -1078,7 +1079,7 @@ def _char_from_weights(self, mdict):
10781079
hdict = {}
10791080
ddict = mdict.copy()
10801081
while ddict:
1081-
highest = max((x.inner_product(self._space.rho()),x) for x in ddict)[1]
1082+
highest = max((x.inner_product(self._space.rho()), x) for x in ddict)[1]
10821083
if not highest.is_dominant():
10831084
raise ValueError("multiplicity dictionary may not be Weyl group invariant")
10841085
sdict = self._irr_weights(highest)
@@ -1279,8 +1280,10 @@ def dual(self):
12791280

12801281
def highest_weight(self):
12811282
"""
1282-
This method is only available for basis elements. Returns the
1283-
parametrizing dominant weight of an irreducible character.
1283+
Return the parametrizing dominant weight
1284+
of an irreducible character.
1285+
1286+
This method is only available for basis elements.
12841287
12851288
EXAMPLES::
12861289
@@ -1323,7 +1326,7 @@ def __pow__(self, n):
13231326
n = -n
13241327

13251328
res = self
1326-
for i in range(n-1):
1329+
for i in range(n - 1):
13271330
res = self * res
13281331
return res
13291332

@@ -1371,13 +1374,12 @@ def symmetric_power(self, k):
13711374
if k == 1:
13721375
return self
13731376
ret = par.zero()
1374-
for r in range(1, k+1):
1375-
adam_r = self._adams_operation_helper(r)
1376-
ret += par.linear_combination((par._product_helper(adam_r, l), c) for (l, c) in self.symmetric_power(k-r))
1377-
dd = {}
1377+
for r in range(1, k + 1):
1378+
adam_r = self._adams_operator_helper(r)
1379+
ret += par.linear_combination((par._product_helper(adam_r, l), c)
1380+
for l, c in self.symmetric_power(k - r))
13781381
m = ret.weight_multiplicities()
1379-
for l in m:
1380-
dd[l] = m[l]/k
1382+
dd = {key: val / k for key, val in m.items()}
13811383
return self.parent().char_from_weights(dd)
13821384

13831385
@cached_method
@@ -1410,8 +1412,8 @@ def exterior_power(self, k):
14101412
if k == 1:
14111413
return self
14121414
ret = par.zero()
1413-
for r in range(1,k+1):
1414-
adam_r = self._adams_operation_helper(r)
1415+
for r in range(1, k + 1):
1416+
adam_r = self._adams_operator_helper(r)
14151417
if is_even(r):
14161418
ret -= par.linear_combination((par._product_helper(adam_r, l), c) for (l, c) in self.exterior_power(k-r))
14171419
else:
@@ -1422,7 +1424,7 @@ def exterior_power(self, k):
14221424
dd[l] = m[l]/k
14231425
return self.parent().char_from_weights(dd)
14241426

1425-
def adams_operation(self, r):
1427+
def adams_operator(self, r):
14261428
"""
14271429
Return the `r`-th Adams operation of ``self``.
14281430
@@ -1436,12 +1438,14 @@ def adams_operation(self, r):
14361438
EXAMPLES::
14371439
14381440
sage: A2 = WeylCharacterRing("A2")
1439-
sage: A2(1,1,0).adams_operation(3)
1441+
sage: A2(1,1,0).adams_operator(3)
14401442
A2(2,2,2) - A2(3,2,1) + A2(3,3,0)
14411443
"""
1442-
return self.parent().char_from_weights(self._adams_operation_helper(r))
1444+
return self.parent().char_from_weights(self._adams_operator_helper(r))
14431445

1444-
def _adams_operation_helper(self, r):
1446+
adams_operation = adams_operator
1447+
1448+
def _adams_operator_helper(self, r):
14451449
"""
14461450
Helper function for Adams operations.
14471451
@@ -1455,14 +1459,11 @@ def _adams_operation_helper(self, r):
14551459
EXAMPLES::
14561460
14571461
sage: A2 = WeylCharacterRing("A2")
1458-
sage: A2(1,1,0)._adams_operation_helper(3)
1462+
sage: A2(1,1,0)._adams_operator_helper(3)
14591463
{(3, 3, 0): 1, (3, 0, 3): 1, (0, 3, 3): 1}
14601464
"""
14611465
d = self.weight_multiplicities()
1462-
dd = {}
1463-
for k in d:
1464-
dd[r*k] = d[k]
1465-
return dd
1466+
return {r * key: val for key, val in d.items()}
14661467

14671468
def symmetric_square(self):
14681469
"""
@@ -1701,14 +1702,14 @@ def irreducible_character_freudenthal(hwv, debug=False):
17011702
for alpha in positive_roots:
17021703
mu_plus_i_alpha = mu + alpha
17031704
while mu_plus_i_alpha in mdict:
1704-
accum += mdict[mu_plus_i_alpha]*(mu_plus_i_alpha).inner_product(alpha)
1705+
accum += mdict[mu_plus_i_alpha] * (mu_plus_i_alpha).inner_product(alpha)
17051706
mu_plus_i_alpha += alpha
17061707
if accum == 0:
17071708
next_layer[mu] = 0
17081709
else:
17091710
hwv_plus_rho = hwv + rho
17101711
mu_plus_rho = mu + rho
1711-
next_layer[mu] = ZZ(2*accum)/ZZ((hwv_plus_rho).inner_product(hwv_plus_rho)-(mu_plus_rho).inner_product(mu_plus_rho))
1712+
next_layer[mu] = ZZ(2 * accum) / ZZ((hwv_plus_rho).inner_product(hwv_plus_rho) - (mu_plus_rho).inner_product(mu_plus_rho))
17121713
current_layer = next_layer
17131714
return mdict
17141715

@@ -1786,7 +1787,7 @@ def __init__(self, parent, prefix):
17861787
self._base_ring = parent._base_ring
17871788
if prefix is None:
17881789
# TODO: refactor this fragile logic into CartanType's
1789-
if self._parent._prefix.replace('x','_').isupper():
1790+
if self._parent._prefix.replace('x', '_').isupper():
17901791
# The 'x' workaround above is to support reducible Cartan types like 'A1xB2'
17911792
prefix = self._parent._prefix.lower()
17921793
elif self._parent._prefix.islower():
@@ -1878,7 +1879,7 @@ def product_on_basis(self, a, b):
18781879
sage: a2(1,0,0) * a2(0,1,0) # indirect doctest
18791880
a2(1,1,0)
18801881
"""
1881-
return self(a+b)
1882+
return self(a + b)
18821883

18831884
def some_elements(self):
18841885
"""
@@ -2012,7 +2013,7 @@ def wt_repr(self, wt):
20122013
sage: [G2.ambient().wt_repr(x) for x in G2.fundamental_weights()]
20132014
['g2(1,0)', 'g2(0,1)']
20142015
"""
2015-
return self._prefix+self.parent()._wt_repr(wt)
2016+
return self._prefix + self.parent()._wt_repr(wt)
20162017

20172018
def _repr_term(self, t):
20182019
"""
@@ -2118,9 +2119,7 @@ def shift(self, mu):
21182119
[g2(2,2), g2(1,3)]
21192120
"""
21202121
d1 = self.monomial_coefficients()
2121-
d2 = {}
2122-
for nu in d1:
2123-
d2[mu + nu] = d1[nu]
2122+
d2 = {mu + nu: val for nu, val in d1.items()}
21242123
return self.parent()._from_dict(d2)
21252124

21262125
def demazure(self, w, debug=False):
@@ -2228,7 +2227,7 @@ def demazure_lusztig(self, i, v):
22282227
if i in self.parent().space().index_set():
22292228
rho = self.parent().space().from_vector_notation(self.parent().space().rho(), style="coroots")
22302229
inv = self.scale(-1)
2231-
return (-inv.shift(-rho).demazure([i]).shift(rho)+v * inv.demazure([i])).scale(-1)
2230+
return (-inv.shift(-rho).demazure([i]).shift(rho) + v * inv.demazure([i])).scale(-1)
22322231
elif isinstance(i, list):
22332232
if not i:
22342233
return self

0 commit comments

Comments
 (0)